Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Where(a => dbContext.dbSet.Where(b=>a.XX == b.XX).Any() 报错 #216

Closed
tky753 opened this issue Feb 26, 2020 · 1 comment
Closed

.Where(a => dbContext.dbSet.Where(b=>a.XX == b.XX).Any() 报错 #216

tky753 opened this issue Feb 26, 2020 · 1 comment

Comments

@tky753
Copy link
Contributor

tky753 commented Feb 26, 2020

public class Song
{
    public long Id { get; set; }
    public string Name { get; set; }
}

public class Author
{
    public long Id { get; set; }
    public long SongId { get; set; }
    public string Name { get; set; }
}

public class TestDbContext : DbContext
{
    public TestDbContext(IFreeSql orm) : base(orm, null)
    {
    }
    public DbSet<Song> Songs { get; set; }
    public DbSet<Author> Authors { get; set; }
}

......
IFreeSql fsql = ......
var context = new TestDbContext(fsql);

var sql = context.Songs
    .Where(a =>
        context.Authors
            //.Select  //加上这句就不报错,不加上报 variable 'a' of type 'Song' referenced from scope '', but it is not defined
            .Where(b => b.SongId == a.Id)
            .Any())
    .ToSql(a => a.Name);
@2881099
Copy link
Collaborator

2881099 commented Feb 26, 2020

是的,lambda Invoke 出错,这里脱离了上下文

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants