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

  • Home
  • SEARCH
  • 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 768513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:11:39+00:00 2026-05-14T18:11:39+00:00

I have Two Many-To-Many tables which I need to write a Entity Framework Linq

  • 0

I have Two Many-To-Many tables which I need to write a Entity Framework Linq query for. All I want to do is to retrieve any People from the “People” table who have a relation to the Company ID = 7.

Can someone give me an idea of what that would look like?

The tables look something like:

People,
ID PK,
Title,
Forename,
Surname

People_Companies
PersonID PK,
CompanyID PK,

Companies
ID PK,
CompanyNumber,
CompanyName,
CompanyType,

The SQL looks like this:

SELECT     People_Companies.PersonID, People_Companies.CompanyID,Companies.ID,Companies.CompanyNumber, Companies.CompanyName, 
                  Companies.CompanyType, People.ID AS Expr1, People.Title, People.Forename, People.Surname, People_Companies.PersonID AS Expr2, People_Companies.CompanyID AS Expr3, Companies.ID AS Expr4, Companies.CompanyNumber AS Expr5, Companies.CompanyName AS Expr6
FROM         People INNER JOIN
                  People_Companies ON People.ID = People_Companies.PersonID INNER JOIN
                  Companies ON People_Companies.CompanyID = Companies.ID
WHERE     (People_Companies.CompanyID = 7)
  • 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-05-14T18:11:39+00:00Added an answer on May 14, 2026 at 6:11 pm

    try

    var q = context.People.Where(p => p.Companies.Any(c => c.CompanyId == 7)).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables (renamed/refactored for illustrative purposes) with a Many-To-Many relationship in an
I have two tables that are joined together. A has many B Normally you
Lets say I have two tables - child and parent with many-to-one relation. What
I have a one to many relationship between two tables. The many table contains
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two entities Foo and Bar with a Many to Many relationship between
I have two entities, Entity1 and Entity2, on a one to many relationship. On
I have two applications written in Java that communicate with each other using XML
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two elements: <input a> <input b onclick=...> When b is clicked, I

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.