WCF数据服务(OData),具有继承限制的查询?

Mat*_*étu 6 inheritance entity-framework entity-framework-4 wcf-data-services odata

项目:使用内部EF4 CTP5代码优先方法的WCF数据服务.

我配置了具有继承(TPH)的实体.查看有关此主题的上一个问题:

以前关于多个实体的问题 - 同一个表

映射效果很好,EF4上的单元测试确认查询运行顺利.

我的实体看起来像这样:

  • ContactBase(摘要)
  • Customer(继承自ContactBase),此实体还具有针对其他实体的多个Navigation属性
  • 资源(继承自ContactBase)

我已配置了一个鉴别器,因此Customer和Resource都映射到同一个表.同样,在Ef4的观点上,每个事情都可以正常工作(单元测试所有绿色!)

但是,当通过WCF数据服务公开这个DBContext时,我得到: - CustomerBases设置暴露(客户和资源集似乎是隐藏的,是设计吗?) - 当我在客户上查询Odata时,我收到此错误:

Navigation Properties are not supported on derived entity types. Entity Set 'ContactBases' has a instance of type 'CodeFirstNamespace.Customer', which is an derived entity type and has navigation properties. Please remove all the navigation properties from type 'CodeFirstNamespace.Customer'. 
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

at System.Data.Services.Serializers.SyndicationSerializer.WriteObjectProperties(IExpandedResult expanded, Object customObject, ResourceType resourceType, Uri absoluteUri, String relativeUri, SyndicationItem item, DictionaryContent content, EpmSourcePathSegment currentSourceRoot)
at System.Data.Services.Serializers.SyndicationSerializer.WriteEntryElement(IExpandedResult expanded, Object element, ResourceType expectedType, Uri absoluteUri, String relativeUri, SyndicationItem target)
at System.Data.Services.Serializers.SyndicationSerializer.<DeferredFeedItems>d__b.MoveNext()
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItems(XmlWriter writer, IEnumerable`1 items, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeedTo(XmlWriter writer, SyndicationFeed feed, Boolean isSourceFeed)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeed(XmlWriter writer)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteTo(XmlWriter writer)
at System.Data.Services.Serializers.SyndicationSerializer.WriteTopLevelElements(IExpandedResult expanded, IEnumerator elements, Boolean hasMoved)
at System.Data.Services.Serializers.Serializer.WriteRequest(IEnumerator queryResults, Boolean hasMoved)
at System.Data.Services.ResponseBodyWriter.Write(Stream stream)
Run Code Online (Sandbox Code Playgroud)

似乎是对WCF数据服务的限制......是吗?在Web上可以找到关于WCF数据服务(OData)和继承规范的文档.

我怎样才能超越这个例外?我需要在派生实体上使用这些导航属性,并且继承似乎是使用Ef4 CTP5在同一个表上提供2个entites映射的唯一方法...

有什么想法吗?

小智 2

目前,WCF 数据服务不支持派生类型的导航属性。这是一个已知的限制,我们目前正在努力在下一个版本中启用此功能。

目前,解决方法是将所有导航属性放入该集引用的类型。在您的示例中,您可以将实体集类型设置为客户,而不是 ContactBase 吗?

希望这可以帮助。谢谢普拉蒂克