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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:26:30+00:00 2026-06-08T12:26:30+00:00

Here is a query I’m working on in Entity Framework 5.0.0 RC (code first)

  • 0

Here is a query I’m working on in Entity Framework 5.0.0 RC (code first) with .NET 4.0

I’m new to Entity Framework, so I’m still getting my head around how to structure the queries, particularly around selecting “child” related data.

I’m using “eager loading” so I get all of the related data at once. But I’m having a problem in that not all of the Drops are being retrieved.

var loads = context.Loads
            .Include(
                p => p.Device
            )
            .Include(
                p => p.Drops.Select(
                    a => a.Customer
                )
            ).Include(
                q => q.Drops.Select(
                   b => b.Items.Select(
                       c => c.Product
                   )
                )
            ).Where(
                u => u.Id.Equals(id)
            );

The problem is that in the generated SQL query, the Customers are being INNER JOINED to the Drops, thus excluding Drops which don’t have a Customer.

So how do I make it do a LEFT JOIN between those two entities?

.Include appears to do left joins – so why not .Select ?

Is there a method other than .Select that I can use which will do a LEFT JOIN ?


UPDATE

After chatting with Amiram I realised that I had set my Drop model up incorrectly. I needed to set the CustomerID column to be optional:

public class Drop
{
    public int Id { get; set; }
    public int? CustomerId { get; set; }
    public int LoadId { get; set; }
    public DateTime Date { get; set; }

    public virtual Customer Customer { get; set; }
    public virtual ICollection<DropItem> Items { get; set; }
}

I should have immediately thought of this, but to be honest I was put off by the fact that .Include() always does a LEFT JOIN, regardless of the cardinality in the relationship of the models. I was thinking .Select() must have some similar behaviour, but no it was just obeying how the model was configured 🙂

  • 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-08T12:26:31+00:00Added an answer on June 8, 2026 at 12:26 pm

    The drops are inner joined with customers since Drop.CustomerID is of type int and not nullable int (Look in the chat).

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

Sidebar

Related Questions

Here's the query I'm trying to convert into Linq: SELECT R.Code, R.FlightNumber, S.[Date], S.Station,
Here is the query that I am working on: SELECT `unitid`, `name` FROM apartmentunits
DueDate Table structure my query here is how to check automatically in php that
I have seen a similar query here But I want to use XNA framework
Got this here query: EXPLAIN SELECT persons.id AS id, ppm.first FROM myschema.persons INNER JOIN
I have a query here pulling data from MySQL database. It's working great.But what
Working on a SQL query here, I have an ID column that I created
Trying to use Linq with some Entity objects to do a crafty query here.
I have a query here regarding the value given to the update attribute of
I'm stuck with another coordinates related query here. I have a number of CSV

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.