WCF data services (OData), query with inheritance limitation?
Posted
by
Mathieu Hétu
on Stack Overflow
See other posts from Stack Overflow
or by Mathieu Hétu
Published on 2011-01-16T17:48:25Z
Indexed on
2011/01/16
17:53 UTC
Read the original article
Hit count: 249
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?
© Stack Overflow or respective owner