12

I have a request like this one

SELECT 
[EstimateId], 
[CreationUserId], 
[EstimateStatusValueId], 
[LanguageId], 
[LocationId], 
[EstimatorUserId], 
[FilterUnitSystemTypeId], 
[EstimateNumber], 
[RevisionNumber], 
[CreationDate], 
[ModificationDate], 
[ProjectDescription], 
[IsBsdq], 
[ClosingDate], 
[ClosingTime], 
[ClosingUpdatedOn], 
[DeadLineDate], 
[IsReceived], 
[Inclusion], 
[Exclusion], 
[Misc], 
[Note], 
[WorkDeadLines], 
[Comments], 
[Validity], 
[PlansLocation], 
[PlansReceivedFrom], 
[Price]
FROM [Estimate].[Estimates] 
ORDER BY [ClosingDate] ASC, [ClosingTime] ASC

When i run this query in SSMS i get a executing time of 953ms, but when i run this query from a Linq Query in my C# i get a executing time of 1813ms.

The Linq Query use the ".Net SqlClient Data Provider" and is issued against EntityFramework (EDMX file). Is this can be an issue ?

Does anybody knows why i have a big difference between execution times of those requests that are the same but execute from different context against the same database ?

I verified all execution plans of both request and they use the same index to satisfy their respective query.

To see the execution plan of the C# request i use the SQL profiler to trap the Show Plan XML event and i compare it to the one of SSMS and both are the same.

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536
Nico
  • 1,062
  • 1
  • 9
  • 18

3 Answers3

6

Is this consistent, time after time?

I see a CPU difference which could be compile time. Are there any LINQ settings that affect this?

Edit:

  • Capture the plans in Profiler
  • Are you sure the SQL is the same in Profiler?
gbn
  • 70,237
  • 8
  • 167
  • 244
4

I think that the problem is in the EDMX file use to generate queries from the C# app.

I found those links that explain the case.

Code Project

Stackoverflow-1

Stackoverflow-2

Nico
  • 1,062
  • 1
  • 9
  • 18
3

You will want to look at the Execution plans for the two queries and see where they are different.

mrdenny
  • 27,106
  • 2
  • 44
  • 81