Reputation: 5299
I have a two LINQ expressions:
var servicesAll = servisesGroup.Services.Where().ToList();
var serviceCompleted =
servisesGroup.Services.Where(t => t.Events.Any(k => k.IdEventType == 7))
.ToList();
if (serviceCompleted .Count == servicesAll .Count)
{
result = true;
}
What heppens here:
1. I take all services
in service group
.
2. I take all services
in service group
with event type
.
3. And check that all services
in services group
have a event
with this event type
.
Its possible to check that all services
in services group
have an event with event type = 7
in one query?
Upvotes: 0
Views: 42
Reputation: 125620
Sure there is, use All
method:
return servisesGroup.Services
.All(s => s.Events.Any(e => e.IdEventType == 7));
Upvotes: 3