我有一个关于返回我认为是来自服务操作的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