In my Custom ObjectContext class I have my entity collections exposed as IObjectSet so they can be unit-tested. I have run into a problem when I use this ObjectContext in a compiled query and call the "Include" extension method (From Julie Lerman's blog http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-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 does not recognize the method 'System.Linq.IQueryable1[MyPocoObject] Include[MyIncludedPocoObject](System.Linq.IQueryable
1[MyPocoObject], System.String)' method, and this method cannot be translated into a store expression.
If I use this same query on ObjectSet collections rather than IObjectSet it works fine. If I simply run this query without precompiling it works fine. What am I missing here?