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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:56:41+00:00 2026-05-13T13:56:41+00:00

I use Entity Framework v4 (code-only). If I do var result = from person

  • 0

I use Entity Framework v4 (code-only). If I do

var result = from person in context.People.Include("Cars")
             select new { person, person.Houses.Count, bar, foo, etc };

then result.First().Cars is null. If I do this way, it works, but I need Houses.Count:

var result = from person in context.People.Include("Cars")
             select person;

It seems Entity Framework v4 doesn’t work well with object initializers?

The solution for now is this:

var result = from person in context.People.Include("Cars").Include("Houses")
             select person;

But performance is ridiculous, I need to bring House row!

  • 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-13T13:56:41+00:00Added an answer on May 13, 2026 at 1:56 pm

    http://connect.microsoft.com/VisualStudio/feedback/details/527749/join-bug-at-ef4-code-only

    Hello Felipe,

    When Include is applied to a query, it
    injects additional “query span”
    information to the query that is then
    used later on, when the query is
    actually executed. The query span
    information is used to internally
    rewrite the query so that the entities
    that can be reached through the
    specified navigation properties are
    also brought from the database and
    materialized.

    When other query operators are applied
    after Include, we try to preserve this
    query span information. However, the
    query span information specified in
    Include will not flow over a query
    operator that changes the result type
    of the query.

    For instance, In a query like this:
    var result =
    from person in context.People.Include(“Cars”)
    select new { person, person.Houses.Count, bar, foo, etc };

    The result type is changing because of
    the projection operation (select) at
    the end and the final result type of
    the query is no longer the original
    entity type over which Include was
    applied, so the query span information
    is lost. A common recommendation to
    avoid this is to always apply Include
    at the end:

    var result = 
        from person in context.People
        select new { person, person.Houses.Count, bar, foo, etc };
    var resultWithCars =
        result.Include("Cars");
    

    In this case, though, the outcome is
    that Include will throw an exception
    at runtime (as opposed to fail
    silently) because query span cannot
    really be applied to an anonymous
    type.

    All the behavior described above is by
    design, but since it is not possible
    for Include to throw an exception in
    many cases, we have found this to be a
    common source of confusion for
    customers.

    If you want to do a projection into an
    anonymous type like this, and you want
    to obtain the Cars property, there is
    actually a very easy way. Simply
    include the Cars property in the
    projection, like this:

    var result = 
        from person in context.People
        select new { person, person.Cars, person.Houses.Count, bar,
    

    foo, etc };

    We are currently considering some
    improvements to the query span API for
    future versions that might address
    issues like this, so your feedback is
    very appreciated. But since we are not
    planning improvements for the current
    release and we keep future
    improvements in our internal backlog,
    I will proceed to resolve the current
    work item.

    Thanks, Diego Vega Entity Framework
    Team

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

Sidebar

Ask A Question

Stats

  • Questions 289k
  • Answers 289k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What's your compiler? Under gcc, you can use -Wconversion to… May 13, 2026 at 5:31 pm
  • Editorial Team
    Editorial Team added an answer Use this.init(), but that is not the only problem. Don't… May 13, 2026 at 5:31 pm
  • Editorial Team
    Editorial Team added an answer Try this: string input = "9:00 PM"; DateTime result; if… May 13, 2026 at 5:31 pm

Related Questions

I have the need to extend instances of various types at runtime. Most of
I was surprised to find a public letter proposing a vote of no confidence
If I use entity framework with linq to sql to query it and I
I'm starting to use Entity Framework. Let's say I have to Entity from my
I am really having a hard time here. I need to design a Desktop

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.