Linq过滤包括



我有下面的行,并考虑过滤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();
}

最新更新