在我的Custom ObjectContext類中,我的實體集合暴露爲IObjectSet,因此它們可以進行單元測試。我遇到了一個問題,當我在編譯的查詢使用的ObjectContext,並呼籲「包括」擴展方法(朱莉·勒曼的博客http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-5-iobjectset/):IObjectSet包含CompiledQuery的擴展方法錯誤
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到實體無法識別方法「System.Linq的.IQueryable 1[MyPocoObject] Include[MyIncludedPocoObject](System.Linq.IQueryable
1 [MyPocoObject],System.String)'方法,並且此方法不能轉換爲存儲表達式。
如果我在ObjectSet集合而不是IObjectSet上使用這個相同的查詢,它工作正常。如果我只是簡單地運行這個查詢而不進行預編譯,它就能正常工作我在這裏錯過了什麼?
我遇到了同樣的問題,您是否找到解決方案? – Paul 2010-08-08 00:15:40