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
You may be able to do this using an Aggregate, along the lines of:
.Aggregate(new {exists = 0, matches = 0}, (a, g) =>
new {exists = a.exists + 1, matches = a.matches + g > 10 ? 1 : 0})
(Here, g > 10 is my test)
And then simple logic that exists is greater than zero and that exists and matches have the same value.
This avoids running the whole query twice.