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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:33:53+00:00 2026-06-01T15:33:53+00:00

I have a TPT inheritance in my EF model. Where there is a Master

  • 0

I have a TPT inheritance in my EF model. Where there is a “Master” abstract type from which several types inherit, including “Order”. There are 1700000 orders, but master has many more rows corresponding to other types.

We had a strange case in which selecting 50 orders was slower than selecting the same 50 orders, but with some other related entities included. It tracked back to database where the very simple query

select top 50 * from SAM.Master m 
join SAL.[Order] o on o.OrderMasterID = m.MasterID
order by MasterID desc

takes more than a second. (Yes, in our case, one second is actually too much). But this can be made faster either by

  1. Removing order by (about two times faster)
  2. sorting in ascending order (clustered indices are in ascending and can’t be otherwise)
  3. adding option(loop join) (extremely fast)
  4. using left outer join
  5. Adding Where FormTypeID = 1 (the discriminator column in Master table which is 1 for all orders) (two times faster)

actually the only solution that yielded the same result are 3 and 5, but 3 is impossible using Entity Framework (we can’t add hints to queries) and 5 is not fast enough

Any suggestions are greatly appreciated.

  • 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-01T15:33:54+00:00Added an answer on June 1, 2026 at 3:33 pm

    You can use plan guides to obtain the behavior you desire. See Using Query Hints in Plan Guides for an example. The example requires the actual statement text (the T-SQL generated by EF) but you can circumvent the need to obtain the EF generated statement by using sp_create_plan_guide_from_handle.

    On your next project avoid using Class Table Inheritance with a base Master object that every entity derives from…

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

Sidebar

Related Questions

I have a model with TPT inheritance. Location ( abstract ) Street ( derived
Have a bunch of classes which I need to do serialize and deserialize from/to
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have converted devise new session from erb to Haml but doens't work, this is
Have a rather abstract question for you all. I'm looking at getting involved in
I am trying to map a TPT inheritance hierarchy on a legacy database (I
I am searching for motifs in sequences (which have gaps, that's why the regular
Have a group of related projects running in SQL Server 2005 for which I
have a look at the code from an xml file where i am using
I'm having trouble constructing an efficient query in EF4 using type per table (TPT)

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.