Linq for object - include with lambda expression

I have a problem with lite, I really don't know how to fix it. In my example below, I would like to select a list of ProductCategories with active ProductItems.

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

The problem is that I cannot access the productItem Active property in my lambda expression, what is the problem? Do I really think that everything is wrong when I try to write a linq query like the one above?

+3
source share
1 answer

There may be more than one item. You probably want to select the categories in which all elements are active :

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

Source: https://habr.com/ru/post/1732705/


All Articles