I need to check if all definitions contains some specific data. It works fine except the case when GroupBy returns empty collection.
var exist = dbContext.De
Here's the alternative to All
that returns false
if collection is empty:
var collection = Enumerable.Range(0, 0); //empty collection
collection
.Select(IsValid)
.DefaultIfEmpty(false)
.All(b => b);
Or as an extension method:
public static bool AnyAndAll(IEnumerable collection, Func predicate) =>
collection
.Select(predicate)
.DefaultIfEmpty(false)
.All(b => b);