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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:37:06+00:00 2026-06-09T22:37:06+00:00

I have a 1-1 relation in my database and when I use .Include() EF

  • 0

I have a 1-1 relation in my database and when I use .Include() EF generates a horrible query that takes ages to execute (mutliple joins). So I thought – I will write my own query to load those entities. What I tried:

  • I tried using ExecuteStoreQuery, but that was a waste of time since it cannot materialize complex properties
  • I tried using an object query with ESQL, but even if I add a join there the related property is not loaded. And (obviously) if I add an .Include() then EF generates the same horrible query.

So, the question is – is there a way to materialize entities bypassing the SQL queries that EF generates?..

UPDATE: just an example of EF query.

The code:

var query = ctx.EntitySet
               .Include("RelatedProperty")
               .Where("it.SomeFilter=@param", new ObjectParameter(...));
var sql = query.ToTraceString();

And that produces the following SQL (I edited the query to make it more readable):

SELECT
    [Extent1].[SomeField] AS [SomeField],
    /* All remaining Extent1 fields */

    [Join1].[Id1] AS [Id1],
    /* All remaining Join1 fields */

    [Join3].[Id2] AS [Id2]
FROM   [OrderSet] AS [Extent1]
LEFT OUTER JOIN  (
    SELECT
        [Extent2].[SomeField] AS [SomeField],
        /* All remaining Extent2 fields */

        [Extent3].[SomeField] AS [SomeField],
        /* All remaining Extent3 fields */

    FROM  [CustomerSet] AS [Extent2]
    LEFT OUTER JOIN [OrderSet] AS [Extent3] 
        ON [Extent2].[Id] = [Extent3].[Customer_Id] ) AS [Join1] 
        ON [Extent1].[Customer_Id] = [Join1].[Id1]
LEFT OUTER JOIN  (
    SELECT 
        [Extent4].[SomeField] AS [SomeField],
        /* All remaining Extent2 fields */

        [Extent5].[SomeField] AS [SomeField],
        /* All remaining Extent3 fields */

    FROM  [CustomerSet] AS [Extent4]
    LEFT OUTER JOIN [OrderSet] AS [Extent5] 
        ON [Extent4].[Id] = [Extent5].[Customer_Id] ) AS [Join3] 
        ON [Extent1].[Customer_Id] = [Join3].[Id4]
WHERE [Extent1].[SomeFilter] = 'blah'
  • 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-09T22:37:07+00:00Added an answer on June 9, 2026 at 10:37 pm

    is there a way to materialize entities bypassing the SQL queries that EF generates?

    In most cases no because:

    • ExceuteStoreQuery cannot load relatioins
    • ESQL cannot load relations without using Include

    The actual options are:

    • Use two separate queries – one for principal entities and one for dependent entities (you can construct correct where clause from the principal entities). If you have everything correctly configured and you turned off lazy loading EF will fix relation automatically when loading related entities
    • Use .NET 4.5 and map hand written SQL / stored procedure returning two result sets – one for principal entities and one for related entities. This requires manual modification (and manual maintenance) of EDMX file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a many-to-many relation with my database, so I created a sql query
I have a 1:n relation in the database and java objects that represent the
I have a question about Criteria method, one-to-many relation to the database, 'one' is
I have two tables, Products and BundleProducts that have o2o relation with BaseProducts. A
I use Entity Framework 4 and I have parent - child relation with Cascade
I have a one-to-one relation where I use CascadeType.PERSIST. This has over time build
I have a mysql table with items in relation to their order. CREATE DATABASE
In my Rails application, I have a variety of database tables that contain user
I use LINQ to query my MSSQL 2005 database. I want to show several
Along side my existing user database, I have been storing a relation of twitter

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.