我有一個關於返回我認爲是來自服務操作的IQueryable的轉換問題,但顯然是一個DbQuery。WCF數據服務操作投問
更新:我立足我的一些代碼(ServiceOp,返回的IEnumerable)關閉斯科特Hanselman的post here的:
[WebGet]
public IQueryable<Post> GetPopularPosts()
我已經建立了基本的WCF DataService的。根據update bug,我將其定義爲:
public class Api : DataService<ObjectContext>
而不是來自TestDb。我安裝了的createDataSource()爲:
protected override ObjectContext CreateDataSource()
{
var testDb = new TestDb();
var objectContext = ((IObjectContextAdapter)testDb).ObjectContext;
objectContext.ContextOptions.ProxyCreationEnabled = false;
return objectContext;
}
在我InitializeService方法,我稱之爲:
config.SetServiceOperationAccessRule("GetStuff", ServiceOperationRights.AllRead);
我的服務操作:
[WebGet]
public IQueryable<Stuff> GetStuff()
{
var context = new TestDb();
return context.Stuff;
}
的問題是,即使方法完成,context.Stuff中有項目,服務器返回錯誤:
An error occurred while processing this request. Exception has been thrown by the target of an invocation. System.Reflection.TargetInvocationException
...
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery' to type 'System.Linq.IQueryable`
對此有何想法?
你可以在這裏添加上下文代碼。 Stuff和Context中的其他對象之間是否有任何關係? – 2011-03-21 07:16:32