简体   繁体   English

实体框架6编译LINQ查询

[英]Entity Framework 6 Compiled LINQ Query

I'm trying to improve performance of a web application by caching a 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);

The error I receive is at compile time: 我收到的错误是在编译时:

The type 'myEntity' cannot be used as type parameter 'TArg0' in the generic type or method 'System.Data.Entity.Core.Objects.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'. 类型'myEntity'不能在泛型类型或方法'System.Data.Entity.Core.Objects.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'中用作类型参数'TArg0'。 There is no implicit reference conversion from 'myEntity' to 'System.Data.Entity.Core.Objects.ObjectContext'. 没有从'myEntity'到'System.Data.Entity.Core.Objects.ObjectContext'的隐式引用转换。

I'm using EF6 我正在使用EF6

Ok it seems that in EF5 and greater the queries are automatically compiled and there is no need to compile them. 好吧,似乎在EF5及更高版本中,查询会自动编译,无需编译它们。 The ObjectContext is not used anymore, and we have now DbContext: Compiled Query no implicit reference conversion to ObjectContext ObjectContext不再使用了,我们现在有了DbContext: Compiled Query没有对ObjectContext的隐式引用转换

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM