我正在尝试通过缓存查询来提高 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
最佳答案
好吧,在 EF5 和更高版本中,查询似乎是自动编译的,不需要编译它们。 不再使用 ObjectContext,我们现在有了 DbContext: Compiled Query no implicit reference conversion to ObjectContext
另一篇关于编译查询的有趣帖子: http://blog.codinghorror.com/compiled-or-bust/
关于c# - Entity Framework 6 编译的 LINQ 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26191721/