1

私は単純なEFクエリを与えました

return context.GlobalEntities
.Where(ge => ge.IsActive == true)  
.ToList()

これは、次の SQL クエリに変換されます

SELECT 
[Extent1].[GlobalEntityId] AS [GlobalEntityId], 
[Extent1].[GlobalEntityName] AS [GlobalEntityName], 
[Extent1].[GlobalEntityAlias] AS [GlobalEntityAlias], 
[Extent1].[GlobalEntityTypeId] AS [GlobalEntityTypeId], 
[Extent1].[IsActive] AS [IsActive], 
[Extent1].[CreatedBy] AS [CreatedBy], 
[Extent1].[CreatedAt] AS [CreatedAt], 
[Extent1].[ChangedBy] AS [ChangedBy], 
[Extent1].[ChangedAt] AS [ChangedAt], 
[Extent1].[EmailAddress] AS [EmailAddress], 
[Extent1].[AverageActionTimeInHrs] AS [AverageActionTimeInHrs], 
[Extent1].[AverageCreationTimeInHrs] AS [AverageCreationTimeInHrs]
FROM [dbo].[GlobalEntity] AS [Extent1]
WHERE 1 = [Extent1].[IsActive]

上記のコードを実行すると、実行に 45 秒かかりますが、SSMS から同じクエリを実行すると、1 秒しかかかりません。

エンティティ フレームワークが単純なクエリを実行するのに時間がかかる理由についてのアイデア。これがSQLプロファイラーの言うことです

SQL:BatchCompleted  SELECT 
[Extent1].[GlobalEntityId] AS [GlobalEntityId], 
[Extent1].[GlobalEntityName] AS [GlobalEntityName], 
[Extent1].[GlobalEntityAlias] AS [GlobalEntityAlias], 
[Extent1].[GlobalEntityTypeId] AS [GlobalEntityTypeId], 
[Extent1].[IsActive] AS [IsActive], 
[Extent1].[CreatedBy] AS [CreatedBy], 
[Extent1].[CreatedAt] AS [CreatedAt], 
[Extent1].[ChangedBy] AS [ChangedBy], 
[Extent1].[ChangedAt] AS [ChangedAt], 
[Extent1].[EmailAddress] AS [EmailAddress], 
[Extent1].[AverageActionTimeInHrs] AS [AverageActionTimeInHrs], 
[Extent1].[AverageCreationTimeInHrs] AS [AverageCreationTimeInHrs]
FROM [dbo].[GlobalEntity] AS [Extent1]
WHERE 1 = [Extent1].[IsActive]  

Application Name: EntityFramework   
NTUserName: user
CPU: 187    
Reads: 1357 
Writes: 0   
Duration: 45157 
ProcessID: 9520 
StartTime: 2012-07-06 10:38:40.797  
End TIme: 2012-07-06 10:39:25.953       
4

0 に答える 0