1

The below query is returning error:

The property expression is not valid. The expression should represent a property access: 't => t.MyProperty'.

var list = this.DataContext
    .GetDbSet<Table1>()
    .Include(t => t.Table2.Where(i=>i.Active == true))
    .Include("Table2.Table3")
    .ToListAsync();

How can achieve the above query?

Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28
difi brasad
  • 289
  • 2
  • 13
  • 1
    Does this answer your question? [Linq Query with a Where clause in an Include statement](https://stackoverflow.com/questions/33528223/linq-query-with-a-where-clause-in-an-include-statement) – Raymond Reddington Jan 23 '20 at 07:14
  • @ZavenZareyan I have tried using "any" but it returns all the data – difi brasad Jan 23 '20 at 07:25

1 Answers1

4

Filter cannot work in include. You need to download Z.EntityFramework.Plus.EFCore from nuget. And use code below

var list = this.DataContext
.GetDbSet<Table1>()
.IncludeFilter(t => t.Table2.Where(i=>i.Active == true))
.ThenInclude(x => x.Table3)
.ToListAsync();

Alternative one

var list = this.DataContext
.GetDbSet<Table1>()
.Include(t => t.Table2)
.ThenInclude(x => x.Table3)
.ToListAsync();
list.Table2 = list.Table2.Where(x => x.Active == true); 
Asherguru
  • 1,687
  • 1
  • 5
  • 10