WebApi OData v4 ComlexType cannot have EntityType

We used WebApi OData v 3 and had a pair of ComplexType

entities defined in the entity data model containing the EntitySet

entities.

When we go to OData v 4 and when modelBulder.GetEdmModel()

we step, we get an InvalidOperationException. The complex type "Foo" refers to the entity "Bar" through the "Bar" property.

I look at the spec and see a thing called "abstract entity type" which is a type that contains entity types. I don't see this in the WebApi OData code, so I hope all I have to do is declare EntityType

that doesn't have a key and I get it.

No cubes. Creating my Foo

type a EntityType

(execute modelBuilder.AddEntityType(typeof(Foo))

instead modelBuilder.AddComplexType(typeof(Foo))

) gives InvalidOperationException "Entity" Foo "does not have a specific key."

Is there a clean way to use entity-data to use ComplexType

or EntityType

?

One clean but painful solution would be to make even more classes, which are essentially my objects, that have been renamed and added to the model like ComplexType

so that I can return data as a complex type (I would include casting operators from object types to the corresponding complex types so that they can be used interchangeably in client code). Obviously, I don't want to go through this pain for something that worked great before moving to OData v4.

Much easier, but not in a clean way (and I did it and it works) involves inserting an unused key into each now EntityType

, which used to be ComplexType

like this:

/// <summary>
/// Gets or sets the not used "key" property
/// </summary>
/// <remarks>
/// OData v4 seems to have broken the ability of a complex type to hold 
/// an entity type. In the spec, there is the notion of an abstract 
/// entity type - an entity type that does not have a key. But, it 
/// appears v4 doesn't support abstract entity types. Hence, this "key".
/// </remarks>
[Key]
public int NotUsed { get; set; }

      

+3


source to share


1 answer


It is part of the V4 protocol that ODataLib for OData V4 has not yet implemented (thus, the Web API for OData V4 does not support defining such a model as it is based on ODataLib and other core libraries). Please open a Github issue at https://github.com/odata/odata.net/issues to ask for it and help track it.



+1


source







All Articles