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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:09:45+00:00 2026-06-14T20:09:45+00:00

Ok, lets say you have two tables: Order and OrderLine and for some reason

  • 0

Ok, lets say you have two tables: Order and OrderLine and for some reason they do not have a foreign key relationship in the database (it’s an example, live with it). Now, you want to join these two tables using Entity Framework and you cook up something like this:

        using (var model = new Model())
        {
            var orders =  from order in model.Order
                          join orderline in model.OrderLine on order.Id equals orderline.OrderId into orderlines
                          from ol in orderlines.DefaultIfEmpty()
                          select new {order = order, orderlines = orderlines};

        }

Now, the above will produce orders and orderlines, left-joined and all, but it has numerous issues:

  1. It’s plain ugly
  2. It returns an anonymous type
  3. It returns multiple instances of the same order and I you have to do Distinct() on the client side because orders.Distinct() fails.

What I am looking for is a solution which is:

  1. Pretty
  2. Returns a statically well-known type instead of the anonymous type (I tried to project the query result, but I got into problems with the OrderLines)
  3. Runs Distinct on the server side

Anyone?

  • 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-14T20:09:46+00:00Added an answer on June 14, 2026 at 8:09 pm

    Even if the database tables do not have a foreign key relationship setup, you can configure Entity Framework as if they do.

    Add an OrderDetails navigation property to your Order class and then just query Orders.

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

Sidebar

Related Questions

Lets say I have data in two tables. In one I have Order ID
I have two tables. Lets say they look like this Table Sports: Column 1:
I have two tables lets say employees and order, both table have millions of
Have have two tables in two different databases: Lets say i have Database users
Lets say I have two tables - Cat and Cat owner that are linked
Lets say I have two tables tblA ( tableAID INT IDENTITY(1,1), foo VARCHAR(100)) tblB
I have two tables, lets say table1 and table2 with common columns, id and
Lets say I have two tables like this: person: id, first_name, last_name, phone_id phone:
Lets say i have two tables EMPLOYEE and INCHARGE_ROOM , EMPLOYEE.INCHARGE_ROOMS has | delimted
Lets say I have two tables, one for transactions, and another table who's primary

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.