© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
20 replies
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
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
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Need help with a linq query
C#CC# / help
3y ago
❔ Help with linq query
C#CC# / help
4y ago
❔ Linq Query HELP
C#CC# / help
3y ago
Help with Linq
C#CC# / help
4y ago