Мне нужно проверить, содержат ли все определения некоторые конкретные данные. Он отлично работает, за исключением случая, когда GroupBy возвращает пустую коллекцию.
var exist = dbContext.Definitions
.Where(x => propertyTypeIds.Contains(x.PropertyTypeId) && x.CountryId == countryId)
.GroupBy(x => x.PropertyTypeId)
.All(...some condition...);
Как переписать это, чтобы All вернул false в пустую коллекцию?
UPDATE: Это LINQ to SQL, и я хотел выполнить это в одном вызове.
UPDATE2: Я думаю, что это работает:
var exist = dbContext.Definitions
.Where(x => propertyTypeIds.Contains(x.PropertyTypeId) && x.CountryId == countryId)
.GroupBy(x => x.PropertyTypeId)
.Count(x => x
.All(...some condition...)) == propertyTypeIds.Count;