So I have 3 main tables (the data is not important):
- Customer
- Group
- Employee
And a couple of “many-to-many” tables to join the other 3 tables:
- GroupCustomer
- GroupEmployee
In essence, a customer can belong to many groups, and an employee can belong to many groups.
So now lets say I have queried for a specific Customer. So I have something like:
Customer customer1 = GetCustomer1();
Now I want to get a count of distinct employees that are in any group that the customer is also in…
int count = customer1.GroupCustomers.SomeLinqMagicGoesHere
So, what is the Linq magic that I need?
important: The relationships are generated using linq-to-sql
Some desired input/output if it help explain my needs:
Customer
--------
C1
C2
GroupCustomer
--------
C1 | G1
C1 | G2
C2 | G1
Group
--------
G1
G2
GroupEmployee
--------
E1 | G1
E1 | G2
E2 | G2
Employee
--------
E1
E2
So the count number I want for C1 should be 2. And the count for C2 should be 1.
Hope that hasn’t confused the issue more!
maybe: