LINQ: What returns All () if there is no element?

This is a very simple question, but "everything" is such a bad keyword for google lol.

I want to get all categories where none of its products are updated or have no products.

In other words, get all categories where all its products have not yet been updated, including all categories in which there are no products yet.

Is this the correct expression?

var categs = context.Categories.Where(c => c.Products.All(x => !x.Updated)); 
+8
c # linq entity-framework
source share
2 answers

It returns true . From the documentation (attention):

Return value
true if each element of the original sequence passes the test in the specified predicate, or if the sequence is empty ; otherwise false.

(This is also a logical conclusion. All elements in the sequence do pass the predicate in the same way that all my daughters are more than 10 feet tall. That I don’t have daughters, 'change the truth of the statement :)

For more information on how they work, see the Edulinq blog on Any and All .

+13
source share

All "Determines whether all elements of the sequence satisfy the condition."

MSDN

I think your expression is correct. You get all categories containing products that are not updated.

+4
source share

All Articles