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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:18:45+00:00 2026-06-07T02:18:45+00:00

I am noticing that the Entity Framework is generated some inefficient queries when using

  • 0

I am noticing that the Entity Framework is generated some inefficient queries when using the Find() method. For example here is my C# code.

Model model = unit.Repository.DbSet.Find(model.ID);

Generate Find() Query

DECLARE @p0 int = 1

SELECT 
[Limit1].[ID] AS [ID], 
[Limit1].[UserID] AS [UserID], 
[Limit1].[Started] AS [Started], 
[Limit1].[Updated] AS [Updated], 
[Limit1].[Completed] AS [Completed]
FROM ( SELECT TOP (2) 
        [Extent1].[ID] AS [ID], 
        [Extent1].[UserID] AS [UserID], 
        [Extent1].[Started] AS [Started], 
        [Extent1].[Updated] AS [Updated], 
        [Extent1].[Completed] AS [Completed]
        FROM [dbo].[Table] AS [Extent1]
        WHERE [Extent1].[ID] = @p0
)  AS [Limit1]

It seems to be running a whole other select query which is unnecessary. Here is the output using the SingleOrDefault() method.

Generate SingleOrDefault() Query

DECLARE @p__linq__0 int = 1

SELECT TOP (2) 
[Extent1].[ID] AS [ID], 
[Extent1].[UserID] AS [UserID], 
[Extent1].[Started] AS [Started], 
[Extent1].[Updated] AS [Updated], 
[Extent1].[Completed] AS [Completed]
FROM [dbo].[Table] AS [Extent1]
WHERE [Extent1].[ID] = @p__linq__0

Is there a reason why Find() is generating two selects? Should the Find() method be avoided in favor of the SingleOrDefault() method?

  • 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-07T02:18:47+00:00Added an answer on June 7, 2026 at 2:18 am

    I doubt there is any performance difference between the two, for sql server at least. It looks like the first one just has an extra wrapper around the select. Running a similar query on a database that I have generates the exact same plan, so I would imagine the outer select gets optimized away in the execution plan.

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

Sidebar

Related Questions

Using Ruby 1.8.6 / Rails 2.3.2 I am noticing that any method called on
I want to test my code but I am noticing that some business logic
In backbone.js, I'm noticing that the change and all events on a Model do
I'm using AutoKey (not AutoHotKey), and I'm noticing that multiple scripts are using the
I'm noticing that some of the things that I do with images in my
I'm getting inconstant results using Ext.getCmp on my htmlEditor. I'm noticing that it is
I've an admin account under some team in apple. I noticing that I have
I have been noticing that some software engineering jobs are asking for .NET developers,
I'm noticing that UIView animations using the UIView class methods seem to more or
I started noticing that sometimes when deallocating memory in some of my programs, they

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.