我可以使用一个复杂的数据类型与EF-提供的WCF数据服务没有告诉EF呢?可以使用、数据类型、复杂、数据

2023-09-06 16:24:27 作者:撩污酷野浪

我使用的是实体框架提供的WCF DataService的以暴露的OData端点。我想创建一个服务操作,返回一个新类型。但我得到:

I am using an Entity Framework-provided WCF DataService to expose an OData endpoint. I want to create a Service Operation that returns a new type. But I get:

异常消息为无法加载元数据的返回类型System.Linq.IQueryable 1 [myNameSpace对象+ MyNewType]方法System.Linq.IQueryable 1 [myNameSpace对象+ MyNewType] FlightHours()'。。请参阅服务器日志的更多细节。

The exception message is 'Unable to load metadata for return type 'System.Linq.IQueryable1[MyNamespace+MyNewType]' of method 'System.Linq.IQueryable1[MyNamespace+MyNewType] FlightHours()'.'. See server logs for more details.

我怎样才能让DataService的知道我想它神交MyNewType?我一定要hackily做一个假的实体上的EF的DataContext,也可以我只是补充,它在某种程度上? 这篇文章想出了破解但我希望情况发生了变化或者说,他们错过了什么。

How can I let the DataService know I want it to grok MyNewType? Do I have to hackily make a fake entity on the EF DataContext, or can I simply "add" it in somehow? This post came up with that hack but I was hoping things had changed or that they missed something.

更新与相关链接:

我认为WCF DataService的实体框架:时间跨度支持将得到解决以同样的方式 这个MSDN讨论意味着这样的方法进行思考和自定义源存在,但没有提及EF的。 在2013年6月更新:感谢@dgorissen谁发现了这个可能的反例: WCF数据服务5.0的解决方法返回波苏斯我还没有机会测试此我自己,我不知道为什么它会工作,但也许它会... I assume WCF DataService with Entity Framework: TimeSpan support would be solved the same way. This MSDN discussion implies that methods like this exist for Reflection and Custom sources but make no mention of EF. Jun 2013 update: Thanks to @dgorissen who found this possible counterexample: WCF Data Services 5.0 Workaround for returning POCOs? I haven't had a chance to test this myself, and I don't know why it would work, but maybe it will...

推荐答案

目前旗下有比教这样的类型存在EF没有别的办法。当您使用EF提供商WCF DS,整个元数据完全来自EF,WCF DS不会修改任何(有意义)的方式。

There's currently no other way than to teach the EF that such a type exists. When you use the EF provider for WCF DS, the entire metadata comes solely from EF, WCF DS doesn't modify it in any (meaningful) way.