实体框架6编译LINQ查询

Gio*_*iox 11 c# linq caching entity-framework compiled-query

我正在尝试通过缓存查询来提高Web应用程序的性能.

    public static Func<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>> CompiledDuplicatedResponses =
    CompiledQuery.Compile<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>>(
    (db, hashes) => from r in db.FormResponse
                    from h in db.IndexHASHes
                    from d in hashes
                    where r.id == h.FormResponseID && h.IndexHASHString == d.hash
                    select r);
Run Code Online (Sandbox Code Playgroud)

我收到的错误是在编译时:

类型'myEntity'不能在泛型类型或方法'System.Data.Entity.Core.Objects.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'中用作类型参数'TArg0'.没有从'myEntity'到'System.Data.Entity.Core.Objects.ObjectContext'的隐式引用转换.

我正在使用EF6

Gio*_*iox 19

好吧,似乎在EF5及更高版本中,查询会自动编译,无需编译它们.ObjectContext不再使用了,我们现在有了DbContext: Compiled Query没有对ObjectContext的隐式引用转换

关于编译查询的另一篇有趣帖子:http: //blog.codinghorror.com/compiled-or-bust/