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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:54:33+00:00 2026-05-18T00:54:33+00:00

If I have a model that looks like this: and I do a Linq

  • 0

If I have a model that looks like this:
alt text

and I do a Linq to Entities query like this:

var c = MyContext.Contact.Count();

I’ll get a SQL query that is as big as all out doors!

SELECT 
[GroupBy1].[A1] AS [C1]
FROM ( SELECT 
    COUNT(1) AS [A1]
    FROM   [dbo].[Contacts] AS [Extent1]
    LEFT OUTER JOIN  (SELECT 
        [UnionAll1].[Id] AS [C1]
        FROM  (SELECT 
            [Extent2].[Id] AS [Id]
            FROM [dbo].[Companies] AS [Extent2]
        UNION ALL
            SELECT 
            [Extent3].[Id] AS [Id]
            FROM [dbo].[Employees] AS [Extent3]) AS [UnionAll1]
    UNION ALL
        SELECT 
        [Extent4].[Id] AS [Id]
        FROM [dbo].[Contractors] AS [Extent4]) AS [UnionAll2] ON [Extent1].[Id] = [UnionAll2].[C1]
    LEFT OUTER JOIN  (SELECT 
        [UnionAll3].[Id] AS [C1]
        FROM  (SELECT 
            [Extent5].[Id] AS [Id]
            FROM [dbo].[Suppliers] AS [Extent5]
        UNION ALL
            SELECT 
            [Extent6].[Id] AS [Id]
            FROM [dbo].[Customers] AS [Extent6]) AS [UnionAll3]
    UNION ALL
        SELECT 
        [Extent7].[Id] AS [Id]
        FROM [dbo].[People] AS [Extent7]) AS [UnionAll4] ON [Extent1].[Id] = [UnionAll4].[C1]
)  AS [GroupBy1]

It seems to me that this should be a very simple query that executes over the base type table (Contact in this case) The model that I’ve included here is a watered down sample of what I’m working with. As you can imagine with a hierarchy 6 levels deep rather than 3 the SQL queries on anything other than the most derived types are very expensive.

Is there any way to tweek the query, or the model definition to reduce the unnecessary complexity of this query.

  • 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-18T00:54:33+00:00Added an answer on May 18, 2026 at 12:54 am

    It’s arguably a bug, and will be fixed RSN.

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

Sidebar

Related Questions

I have an object that looks like this: class Model { public string Category
My application I have an application design that looks like this: web application layer
I have an application that manages documents called Notes. Like a blog, Notes can
I have a model with a list property. I have a csv that has
i have 3 tables in my database and i created a entity model from
I'm struggling to model a particular relationship with ActiveRecord. I currently have the following
I have an abstract Content entity in my EF4 model with a concrete subclass,
I am trying to build a domain model that will allow me to manage
I'm pretty much a novice as far as WCF goes and I'm trying to
I'm using the friendly_id plugin to generate SEO-friendly URLS for some of my models.

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.