我有一个精简问题,我真的不知道如何解决。在下面的示例中,我想选择ProductCtemories列表,其中ProductItems处于活动状态。
public IEnumerable<ProductCategory> ListProductCategories()
{
return _entities.ProductCategorySet.Include("ProductItems").Where(x => x.ProductItems.Active == true).ToList();
}
问题是我无法访问我的lambda表达式中的productItem属性Active,有什么问题?当我试图编写像上面那样的linq查询时,我认为总是错误吗?
答案 0 :(得分:6)
可能有多个项目。您可能希望选择所有项目处于活动状态的类别:
return _entities.ProductCategorySet
.Include("ProductItems")
.Where(x => x.ProductItems.All(item => item.Active))
.ToList();