实体框架非常慢

时间:2012-07-06 18:26:54

标签: entity-framework-4.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       

0 个答案:

没有答案