Reputation: 29444
This is a very simple question but "All" is such a bad keyword to google lol.
I want to get all categories, where none of its products are updated, or don't have any products.
In other words, get all categories, where all of its products are not yet updated, including all categories that don't have any products yet.
Is this the right expression?
var categs = context.Categories.Where(c => c.Products.All(x => !x.Updated));
Upvotes: 12
Views: 3183
Reputation: 1499840
It returns true
. From the documentation (emphasis mine):
Return value
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
(This is the logical conclusion too. All of the elements in the sequence do indeed pass the predicate, in the same way that all of my daughters are over 10 feet tall. The fact that I don't have any daughters doesn't change the truth of the statement :)
See my Edulinq blog post on Any
and All
for more details about how they work.
Upvotes: 19