C#C
C#4y ago
Esa

❔ Need help with a LINQ query

Hi,
I could use a bit of help building a LINQ query.
Assume a simple entity like this:

Event
  int EventTypeId
  int CustomerId


Then you have an IEnumerable<Event>. From this collection I want to extract all customer ids that only have eventTypeId == 1 associated with them.
So if there are two events for one customerId, and those two eventTypeIds are 1 and 2 then I don't want that associated customer id.
If both eventTypeIds are 1 then I want that specific customerId. Does that make sense?

Currently I have this
from event in events
group event by event.CustomerId
into customerEvents
where customerEvents.All(event => event.EventTypeId != 2)
select customerEvents


But looking at it it doesn't really make sense. And it doesn't return what I thought it would. Any ideas?
Was this page helpful?