开发者

linq to entity - include with lambda expression

开发者 https://www.devze.com 2022-12-20 15:38 出处:网络
I have a lite problem i don\'t really know how to fix. In my example be开发者_C百科low i would like to select a list of ProductCategories with ProductItems that are active.

I have a lite problem i don't really know how to fix. In my example be开发者_C百科low i would like to select a list of ProductCategories with ProductItems that are active.

public IEnumerable<ProductCategory> ListProductCategories()
        {
            return _entities.ProductCategorySet.Include("ProductItems").Where(x => x.ProductItems.Active == true).ToList();               
        }

The problem is that i can't access productItem property Active in my lambda expression, what is the problem? Do I think totaly wrong when im trying to write a linq query like the one above?


There could be more than one item. You probably want to select the categories where all items are active:

return _entities.ProductCategorySet
                .Include("ProductItems")
                .Where(x => x.ProductItems.All(item => item.Active))
                .ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消