【问题标题】:Entity Framework 6 Compiled LINQ Query实体框架 6 编译的 LINQ 查询
【发布时间】:2014-10-04 10:06:12
【问题描述】:

我正在尝试通过缓存查询来提高 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.Data.Entity.Core.Objects.CompiledQuery.Compile(System.Linq.Expressions.Expression>) 中的类型参数“TArg0” '。没有从“myEntity”到“System.Data.Entity.Core.Objects.ObjectContext”的隐式引用转换。

我正在使用 EF6

【问题讨论】:

  • 你需要ObjectContext对象作为Compile方法的第一个类型参数。

标签: c# linq entity-framework caching compiled-query


【解决方案1】:

好吧,似乎在 EF5 和更高版本中查询是自动编译的,不需要编译它们。 ObjectContext 不再使用,我们现在有了 DbContext: Compiled Query no implicit reference conversion to ObjectContext

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2016-01-14
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    相关资源
    最近更新 更多