WCF数据服务(OData),查询带有继承限制? [英] WCF data services (OData), query with inheritance limitation?

查看:172
本文介绍了WCF数据服务(OData),查询带有继承限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目:使用内部EF4 CTP5的WCF数据服务Code-First方法。



我配置了继承的实体(TPH)。
请参阅有关此主题的上一个问题:



关于多个实体的上一个问题 - 相同的表格



映射运行良好,单元测试EF4确认查询运行顺利。



我的实体看起来像这样:




  • ContactBase(摘要)

  • 客户(继承ContactBase),该实体还有其他实体的几个Navigation属性

  • Resource(继承自ContactBase)



我已经配置了一个鉴别器,因此客户和资源都映射到同一个表。
再次,Ef4的观点(单元测试所有的绿色)都可以正常工作。



然而,当通过WCF数据服务暴露这个DBContext时,我得到:
- CustomerBases设置暴露(客户和资源集合似乎隐藏,是否设计?)
- 当我在客户端查询Odata时,我收到以下错误:

 派生实体类型不支持导航属性。实体集ContactBases具有类型为CodeFirstNamespace.Customer的实例,它是派生实体类型并具有导航属性。请从CodeFirstNamespace.Customer类型中删除所有导航属性。 

Stacktrace:

 code> System.Data.Services.Serializers.SyndicationSerializer.WriteObjectProperties(IExpandedResult expanded,Object customObject,ResourceType resourceType,Uri absoluteUri,String relativeUri,SyndicationItem项目,DictionaryContent内容,EpmSourcePathSegment currentSourceRoot)
在System.Data .Services.Serializers.SyndicationSerializer.WriteEntryElement(扩展的IExpandedResult,Object元素,ResourceType expectedType,Uri absoluteUri,String relativeUri,SyndicationItem target)
在System.Data.Services.Serializers.SyndicationSerializer。< DeferredFeedItems> d__b.MoveNext )
在System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItems(XmlWriter writer,IEnumerable`1 items,Uri feedBaseUri)
在System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeedTo(XmlWriter writer,SyndicationFeed feed,Boolean isSourceFeed )
在System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeed(X mlWriter writer)
在System.ServiceModel.Syndication.Atom10FeedFormatter.WriteTo(XmlWriter writer)
在System.Data.Services.Serializers.SyndicationSerializer.WriteTopLevelElements(扩展的IExpandedResult,IEnumerator元素,Boolean hasMoved)
在System.Data.Services.Serializers.Serializer.WriteRequest(IEnumerator queryResults,Boolean hasMoved)
在System.Data.Services.ResponseBodyWriter.Write(Stream stream)

看起来像WCF数据服务的限制...是吗?
网络上没有关于WCF数据服务(OData)和继承规范的文档数量太多。



我如何超越这个异常?我需要这些派生实体的导航属性,继承似乎是提供与Ef4 CTP5相同的表上的2个对象的唯一方法...



任何想法? / p>

解决方案

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



目前,解决的办法是将所有导航属性设置为所指定的类型由集合。在您的示例中,您可以使实体集类型成为客户,而不是ContactBase?



希望这有帮助。
感谢
Pratik


Project: WCF Data service using internally EF4 CTP5 Code-First approach.

I configured entities with inheritance (TPH). See previous question on this topic:

Previous question about multiple entities- same table

The mapping works well, and unit test over EF4 confirms that queries runs smoothly.

My entities looks like this:

  • ContactBase (abstract)
  • Customer (inherits from ContactBase), this entity has also several Navigation properties toward other entities
  • Resource (inherits from ContactBase)

I have configured a discriminator, so both Customer and Resource map to the same table. Again, everythings works fine on the Ef4 point of view (unit tests all greens!)

However, when exposing this DBContext over WCF Data services, I get: - CustomerBases sets exposed (Customers and Resources sets seems hidden, is it by design?) - When I query over Odata on Customers, I get this error:

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

Stacktrace:

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)

Seems like a limitation of WCF Data services... is it? Not much documentation can be found on the web about WCF Data services (OData) and inheritance specifications.

How can I overpass this exception? I need these navigation properties on derived entities, and inheritance seems the only way to provide mapping of 2 entites on the same table with Ef4 CTP5...

Any thoughts?

解决方案

Currently, WCF data services does not support navigation properties on derived types. This is a known limitation and we are currently working on enabling this for our next release.

Currently, the work around is that you put all the navigation properties to the type refered by the set. In your example, can you make the entity set type be customer, instead of ContactBase?

Hope this helps. Thanks Pratik

这篇关于WCF数据服务(OData),查询带有继承限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆