Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:07:45+00:00 2026-06-15T23:07:45+00:00

So I have 3 main tables (the data is not important): Customer Group Employee

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:07:46+00:00Added an answer on June 15, 2026 at 11:07 pm

    maybe:

    int count = costumer.GroupCustomers
        .SelectMany(gc => gc.Group.GroupEmployees)
        .Select(ge => ge.EmployeeID)
        .Distinct()
        .Count();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a many-to-many database with join tables connecting main data tables through foreign
Ok, here's the condensed form. I have three main tables to draw data from:
Suppose I have two tables Main and Other like the following: Main +----------+-----------------------------------+ |
I have 3 tables I need to join. The contracts table is the main
I have a structure where the main table is USER, other tables include CATEGORY
In SQL Server, I have two tables. One main table with all the data
I have a relational database with one main table linked to other tables with
I have 2 tables: a main APPLICATION table that holds the core data, and
I have 2 tables Main and Maintest. I am using nhibernate to pull data
I have these tables cat (holds main data for categories) id_cat, original name cat_lang

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.