实体框架6.0.2极端缓慢

时间:2013-12-15 14:07:51

标签: c# sql entity-framework

我尝试了NuGet的Entity Framework 6.0.2 Code First。 db中有一行,条件就这么简单(EF生成的sql):

SELECT 
[Extent1].[Id] AS [Id], 
[Extent1].[Name] AS [Name], 
[Extent1].[Practised] AS [Practised], 
[Extent1].[SourceLangId] AS [SourceLangId], 
[Extent1].[TargetLangId] AS [TargetLangId], 
[Extent1].[UserId] AS [UserId]
FROM [dbo].[Dictionary] AS [Extent1]
WHERE ([Extent1].[UserId] = @p__linq__0) AND (@p__linq__0 IS NOT NULL)

我这样叫EF:

IEnumerable<Dictionary> dics = context.Dictionaries.Where(s => s.UserId == userId);

查询执行时间约为15-16秒。当我直接用ADO调用完全相同的sql时,查询执行时间为0,0010017秒 我不确定时间是由sql执行引起的,还是从SQL获取数据到实体。

谢谢

编辑:

Dictionary是Code First实体:

public class Dictionary
{
    [Key]
    [ScaffoldColumn(false)]
    public long Id { get; set; }

    [Display(Name = "Name")]
    [Required]
    [MaxLength(25)]
    public string Name { get; set; }

    public int Practised { get; set; }

    public long SourceLangId { get; set; }
    public virtual Lang SourceLang { get; set; }

    public long TargetLangId { get; set; }
    public virtual Lang TargetLang { get; set; }

    public long UserId { get; set; }
    public virtual User User { get; set; }
}

1 个答案:

答案 0 :(得分:1)

由于EF 6.0.2中的错误,性能很慢

请参阅EF Twitter Account