C# Linq滤波包括
我有下面的一行,正在考虑过滤CustomersPicsC# Linq滤波包括,c#,entity-framework,linq,C#,Entity Framework,Linq,我有下面的一行,正在考虑过滤CustomersPicsisdeleted==true。我该怎么做 List<Customer> _customer = context.Customers .Where(r => r.IsDeleted == IsDeleted) .Include(r=> r.CustomersPics)
isdeleted==true
。我该怎么做
List<Customer> _customer = context.Customers
.Where(r => r.IsDeleted == IsDeleted)
.Include(r=> r.CustomersPics)
.ToList();
List\u customer=context.Customers
.其中(r=>r.IsDeleted==IsDeleted)
.Include(r=>r.CustomersPics)
.ToList();
您不能使用包含扩展方法来做您想做的事情。您可以使用如下方法过滤导航集合属性:
List<Customer> _customer = context.Customers
.Where(r => r.IsDeleted == IsDeleted)
.Include(r=> r.CustomersPics)
.ToList();
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();
}
Linq到SQL和实体框架不支持筛选的包含项。