在我的自定义 ObjectContext 类中,我将实体集合公开为 IObjectSet,因此可以对它们进行单元测试。当我在编译查询中使用此 ObjectContext 并调用“包含”扩展方法时遇到问题(来自 Julie Lerman 的博客http://thedatafarm.com/blog/data-access/agile-entity-framework-4-存储库部分 5-iobjectset/):
public IQueryable<MyPocoObject> RunQuery(MyCustomContext context, int theId)
{
var query = CompiledQuery.Compile<MyCustomContext, int, IQueryable<MyPocoObject>>(
(ctx, id) => ctx.MyPocoObjects.Include("IncludedPocoObject").Where(n => n.IncludedPocoObject.id == id));
return query(context, theId);
}
LINQ to Entities 无法识别方法 'System.Linq.IQueryable 1[MyPocoObject] Include[MyIncludedPocoObject](System.Linq.IQueryable
1[MyPocoObject], System.String)' 方法,并且此方法无法转换为存储表达式。
如果我在 ObjectSet 集合而不是 IObjectSet 上使用相同的查询,它可以正常工作。如果我只是在不预编译的情况下运行此查询,它就可以正常工作。我在这里想念什么?