WCF Data Services (OData) query with inheritance restriction?

Project: WCF data service using the EF4 CTP5 Code-First internal approach.

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

Previous question about multiple entities - same table

The mapping works well, and the unit test on EF4 confirms that the queries run smoothly.

My objects look like this:

  • ContactBase (abstract)
  • The client (inherits from ContactBase), this object also has several navigation properties in relation to other objects.
  • Resource (inherited from ContactBase)

I set up a discriminator, so both clients and resources are mapped to the same table. Again, everything works fine in terms of Ef4 (the unit tests all the greens!)

However, when exposing this DBContext through WCF data services, I get: - The client database sets are exposed (the client and resource sets seem hidden, is it by design?) - When I request Odata for clients, 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) 

Sounds like WCF data service restriction ... doesn't it? Not many documents can be found on the Internet about WCF Data Services (OData) and inheritance specifications.

How can I overcome this exception? I need these navigation properties for derived entities, and inheritance seems to be the only way to ensure that 2 names are displayed in the same table using Ef4 CTP5 ...

Any thoughts?

+6
source share
1 answer

WCF data services do not currently support derived type navigation properties. This is a known limitation, and we are currently working to include this for our next version.

Currently, the work is that all the navigation properties are assigned to the type the set refers to. In your example, can you make the object set type a client rather than ContactBase?

Hope this helps. thanks pratik

+2
source

All Articles