0

Looking at setting up Web API odata and trying to expose the data out of our edmx to it. The problem is that every time i add an entity to the OdataConventionBuilder I get a big nasty error message on load saying:

The complex type 'MyData.AssetReading' refers to the entity type 'MyData.Asset' through the property 'Asset'

It seems for relations defined in the edmx is bombing the webapi odata out about a complex type. Any ideas on how to get around this as the edmx is huge and a rejig of it is pretty much out of the question. Is there a property that I need to set on the Builder.EntitySet or the MapOdataRoute method?

Matt
  • 3,305
  • 11
  • 54
  • 98

1 Answers1

1

This error message is caused by the fact that the current version of Web API for OData V4 doesn't support defining navigation properties on a complex type in the model. I.e. complex type can't refer to entity type(s) yet.

This work is tracked by this GitHub issue: https://github.com/OData/WebApi/issues/65. Weigh in by commenting it if you'd like it to be prioritized.

Yi Ding - MSFT
  • 2,864
  • 16
  • 16
  • 1
    Hi Yim Thanks for the response. Thats a bit annoying, and the issue on github is close to a year old so that doesnt give me much hope. How do we get around the error then? I can't remove all the relationships from the edmx because they are still being used correctly by legacy odata.svc clients. – Matt Mar 05 '15 at 21:15
  • HI Yi Ding, Thats a bummer. Is there anyway when defining the MapODataRoute that I can just tell the builder.GetEdmModel to ignore the relationships by default? Thanks – Matt Mar 09 '15 at 03:07
  • @Raven I think the only mitigation for it would be to build the EDM model using APIs in EdmLib instead of ODataConventionModelBuilder and pass it to MapODataRoute, to avoid auto-relationship recognition. There aren't many samples online about how to do it. But here is a simple one from which you can get a feeling about it: https://github.com/OData/ODataSamples/tree/master/Components/Edm/ODataSamples.Edm – Yi Ding - MSFT Mar 09 '15 at 03:17
  • Yi Ding, from my understanding of looking at the code snippet we will need to pretty much build the edm back up again via code? This is going to take a lot of work, hoping for a better win – Matt Mar 09 '15 at 05:45
  • @Raven sorry. After having consulted a few colleges, there is no other workaround than using EdmLib. – Yi Ding - MSFT Mar 13 '15 at 05:51