我有下面的行,并考虑过滤CustomersPics isdeleted == true
。我怎么做呢?
List<Customer> _customer = context.Customers
.Where(r => r.IsDeleted == IsDeleted)
.Include(r=> r.CustomersPics)
.ToList();
您不能使用Include
扩展方法为所欲为。您可以使用Load
方法过滤导航集合属性,如下所示:
var customers = context.Customers.ToList(); // Make to add some Where clause here and avoid loading all data from Customer table :D
foreach(var customer in customers)
{
context.Entry(customer)
.Collection(p => p.CustomersPics)
.Query()
.Where(p => p.IsDeleted == true)
.Load();
}