カスタム ObjectContext クラスでは、エンティティ コレクションを IObjectSet として公開しているため、単体テストを実行できます。コンパイルされたクエリでこの ObjectContext を使用し、"Include" 拡張メソッドを呼び出すと、問題が発生しました (Julie Lerman のブログhttp://thedatafarm.com/blog/data-access/agile-entity-framework-4-から)リポジトリ-part-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)' メソッドを認識せず、このメソッドはストア式に変換できません。
IObjectSet ではなく ObjectSet コレクションでこの同じクエリを使用すると、正常に動作します。プリコンパイルせずにこのクエリを実行すると、正常に動作します。ここで何が欠けていますか?