WCF 数据服务与EF 4.1 RC Code First - 重写 CreateDataSource,现在如何使用 CurrentDataSource?
我正在使用 EF 4.1 RC Code First 创建 WCF 数据服务 (OData)。我已经重写了 CreateDataSource 方法以使其正常工作,但随后我无法创建返回 IQueryable 或使用 CurrentDataSource
的操作。有没有办法将 CurrentDataSource 属性映射回 DbContext?
这是我的代码:
protected override ObjectContext CreateDataSource()
{
var context = ((IObjectContextAdapter)new NotesnhacContext()).ObjectContext;
context.ContextOptions.ProxyCreationEnabled = false;
return context;
}
[WebGet]
public IQueryable<MusicSheet> GetMusicSheets(int pageIndex, int pageSize)
{
// This doesn't work... I can't access "MusicSheets"
//return CurrentDataSource.MusicSheets.Where(... ... );
}
谢谢。
I'm creating a WCF Data Services (OData) with EF 4.1 RC Code First. I've overrode the CreateDataSource method to make it work, but then I can't create operations that return an IQueryable or using CurrentDataSource
. Is there a way to map CurrentDataSource property back to DbContext?
Here's my code:
protected override ObjectContext CreateDataSource()
{
var context = ((IObjectContextAdapter)new NotesnhacContext()).ObjectContext;
context.ContextOptions.ProxyCreationEnabled = false;
return context;
}
[WebGet]
public IQueryable<MusicSheet> GetMusicSheets(int pageIndex, int pageSize)
{
// This doesn't work... I can't access "MusicSheets"
//return CurrentDataSource.MusicSheets.Where(... ... );
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试 WCF 数据服务的新 CTP - http://blogs.msdn.com/b/astoriateam/archive/2011/03/09/announcing-wcf-data-services-march- 2011-ctp2-for-net4-amp-sl4.aspx
使用此 CTP,不再需要重写 CreateDataSource 方法,并且 CurrentDataSource 是 DBContext 的一个实例。
换句话说,这个CTP完全支持DbContext。
希望这有帮助。
谢谢
普拉蒂克
Can you try the new CTP of WCF Data Services - http://blogs.msdn.com/b/astoriateam/archive/2011/03/09/announcing-wcf-data-services-march-2011-ctp2-for-net4-amp-sl4.aspx
With this CTP, one no longer needs to override the CreateDataSource method, and the CurrentDataSource is an instance of DBContext.
In other words, DbContext is fully supported in this CTP.
Hope this helps.
Thanks
Pratik