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
What about writing your own extension method? (I am pretty sure you will name it better)
public static bool NotEmptyAll(
this IEnumerable collection,
Func predicate)
{
return collection != null
&& collection.Any()
&& collection.All(predicate);
}
Then call it instead of All
var exist = definitions.Where(
x => propertyTypeIds.Contains(x.PropertyTypeId) && x.CountryId == countryId)
.GroupBy(x => x.PropertyTypeId)
.NotEmptyAll(
...some condition...));