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 7762109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:18:35+00:00 2026-06-01T14:18:35+00:00

What is the best solution for many-to-many joins in Entity Framework. It looks like

  • 0

What is the best solution for many-to-many joins in Entity Framework. It looks like in the one project where we used EF after adding the tables to the edmx file it neglected to add the intersection entity i.e.:

With these tables

Customer(CustomerId,...)
CustomerOrder(CustomerId,OrderId)
Order(OrderId,...)

The CustomerOrder table was not added to the edmx so then the tables could not be joined with a conventional (conventional meaning how we used to do it in LINQ to SQL) inner join query e.g.

var q = from c in db.Customers
        join co in db.CustomerOrders on c.CustomerId equals co.CustomerId
        join o in db.Orders on co.OrderId equals o.OrderId
        select a;

As I understand from looking at previously asked questions you could do multiple selects and “join” by specifing conditions in the where clause, or use the intersects keyword. But I would like to know what is the best practice for situations like these.

Say I would like to find out which orders a customer has, how would I go about writing that query.

  • 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-01T14:18:37+00:00Added an answer on June 1, 2026 at 2:18 pm

    Just for clarification, when the two tables are added, the joining table is not part of the edmx, unless it contains more than just the joining table IDs. In the scenario when EF decides to not use the joining table as an entity, each of the other tables should have navigational properties (Orders would have ICollection<Customer> Customers and Customers would have ICollection<Orders>) which allow access to the joining tables without the need to manually join them. In that scenario you would be able to do the following:

    var customer = dbContext.Customers.Include("Orders")
                                      .Where(o => o.Orders.OrderID == 2);
    

    Normally, the navigational properties are lazy loaded, where the object(s) are not in the properties of the entity until they are accessed by code. You can manually tell the framework to load them right away if you know you are going to use them by using the Include method. This method in this example is NOT necessary in order to access the Orders.OrderID value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need create an email list sending to many emails. what is best solution
I've tried my best to find out a solution with the many script questions
best solution for use access in project for database with security i need to
What would be the best solution for programmers like http://vimeo.com/28885655 The people who created
What is the best solution for maintaining backup and revision control on live websites?
What is the best solution for converting WAV files to WMA (and vice versa)
What is the best solution to sanitize output HTML in Rails (to avoid XSS
what is the best solution to import large amounts of records into an MySQL
What's the best solution for authoring HTML5 in Emacs? Is there a mode that
what is the best solution in terms of performance and readability/good coding style to

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.