C# 实体框架6编译LINQ查询
我试图通过缓存查询来提高web应用程序的性能C# 实体框架6编译LINQ查询,c#,linq,entity-framework,caching,compiled-query,C#,Linq,Entity Framework,Caching,Compiled Query,我试图通过缓存查询来提高web应用程序的性能 public static Func<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>> CompiledDuplicatedResponses = CompiledQuery.Compile<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>&
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);
public static Func编译的重复响应=
CompiledQuery.Compile(
(db,hashes)=>从db.FormResponse中的r开始
从h开始,单位为db
从散列中的d开始
其中r.id==h.FormResponseID&&h.IndexHASHString==d.hash
选择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: 另一篇关于编译查询的有趣文章:
您需要
ObjectContext
对象作为Compile
方法的第一个类型参数。