Entity Framework 6 Compiled LINQ Query

北战南征 提交于 2019-12-18 05:44:13

问题


I'm trying to improve performance of a web application by caching a query.

    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>)'. There is no implicit reference conversion from 'myEntity' to 'System.Data.Entity.Core.Objects.ObjectContext'.

I'm using EF6


回答1:


Ok it seems that in EF5 and greater the queries are automatically compiled and there is no need to compile them. The ObjectContext is not used anymore, and we have now DbContext: Compiled Query no implicit reference conversion to ObjectContext

Another interesting post on Compiled Query: http://blog.codinghorror.com/compiled-or-bust/



来源:https://stackoverflow.com/questions/26191721/entity-framework-6-compiled-linq-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!