Reputation: 3681
With OData, we can set the IsNullable
value for a structural property to false
to say that a property is required.
Is it possible to do something similar for a navigation property?
I have found the TargetMultiplicity
property on EdmNavigationPropertyInfo
which can be set to a value such as EdmMultiplicity.One
. I assumed this would make it required (and may do under the hood) but there doesn't appear to be anything in the metadata to show that it is not nullable so the consumer won't know that it is required.
I am building my metadata and objects at runtime from a database and not using concrete types.
Upvotes: 0
Views: 1152
Reputation: 3380
For you question:
The answer is absolutely Yes.
Let me illustrate form following aspects:
The edm:NavigationProperty element MAY contain the Nullable attribute whose Boolean value specifies whether a navigation target is required for the navigation property. ....
Multiplicity is the concept in OData V3 spec. you can find the definition 10.2.3 The edm:Multiplicity Attribute from here. Because the implementation of OData V4 is migrated from OData V3 library. So, the same definition is reused(not changed) in OData V4 library. However, it should be removed from OData V4 library.
From the OData v4 lib implementation, you can find the following mapping:
a) EdmMultiplicity.ZeroOrOne (IsNullable = true)
b) EdmMultiplicity.One (IsNullable = false)
c) EdmMultiplicity.Many ( Means the collection, while collection is always non-nullable)
So, I say yes.
Let me show the example: If you try the OData sample service: http://services.odata.org/v4/TrippinService/$metadata, you can find Nullable attribute for the navigation property.
--
<Property Name="FlightNumber" Nullable="false" Type="Edm.String"/>
<NavigationProperty Name="From" Nullable="false" Type="Microsoft.OData.SampleService.Models.TripPin.Airport"/>
<NavigationProperty Name="To" Nullable="false" Type="Microsoft.OData.SampleService.Models.TripPin.Airport"/>
<NavigationProperty Name="Airline" Nullable="false" Type="Microsoft.OData.SampleService.Models.TripPin.Airline"/>
</EntityType>
Hope it can help you. Thanks.
Upvotes: 1