Entity Framework 6编译的LINQ查询

本文关键字:LINQ 查询 编译 Framework Entity | 更新日期: 2023-09-27 18:25:28

我正试图通过缓存查询来提高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);

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

类型"myEntity"不能用作泛型类型或方法"System"中的类型参数"TArg0"。数据实体果心对象。CompiledQuery。Compile(System.Linq.Expressions.Expression>)'。没有从"myEntity"到"System"的隐式引用转换。数据实体果心对象。ObjectContext"

我正在使用EF6

Entity Framework 6编译的LINQ查询

好的,在EF5及更高版本中,查询似乎是自动编译的,不需要编译它们。ObjectContext不再使用,现在我们有了DbContext:编译的查询没有到ObjectContext 的隐式引用转换

另一篇关于Compiled Query的有趣文章:http://blog.codinghorror.com/compiled-or-bust/