Can I use a complex datatype with an EF-provided WCF Data Services without telling EF about it?

旧巷老猫 提交于 2019-12-24 10:49:37

问题


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:

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.

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.

Update with relevant links:

  • 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...

回答1:


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.



来源:https://stackoverflow.com/questions/14525606/can-i-use-a-complex-datatype-with-an-ef-provided-wcf-data-services-without-telli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!