OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
856 stars 474 forks source link

Add foreign key information to the associations in the $metadata document #37

Closed LianwMS closed 9 years ago

LianwMS commented 9 years ago

When there is an entity in a model that has an entity that explicitly exposes the foreign key of an association to another entity, make that information visible and available in the $metadata document.

For example:

<EntityType Name="Customer">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="Id" Type="Edm.Int32" Nullable="false" p6:StoreGeneratedPattern="Identity"/>
<Property Name="Name" Type="Edm.String" MaxLength="Max" FixedLength="false" Unicode="true"/>
<NavigationProperty Name="Orders" Relationship="WcfDataServicesForeignKey.Customer_Orders" ToRole="Customer_Orders_Target" FromRole="Customer_Orders_Source"/>
</EntityType>
<EntityType Name="Order">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="Id" Type="Edm.Int32" Nullable="false" p6:StoreGeneratedPattern="Identity"/>
<Property Name="CustomerId" Type="Edm.Int32" Nullable="false"/>
<Property Name="Purchased" Type="Edm.DateTime" Nullable="false"/>
<Property Name="Total" Type="Edm.Double" Nullable="false"/>
</EntityType>
<Association Name="Customer_Orders">
<End Type="WcfDataServicesForeignKey.Customer" Role="Customer_Orders_Source" Multiplicity="1">
<OnDelete Action="Cascade"/>
</End>
<End Type="WcfDataServicesForeignKey.Order" Role="Customer_Orders_Target" Multiplicity="*"/>
<ReferentialConstraint>
<Principal Role="Customer_Orders_Source">
<PropertyRef Name="Id"/>
</Principal>
<Dependent Role="Customer_Orders_Target">
<PropertyRef Name="CustomerId"/>
</Dependent>
</ReferentialConstraint>
</Association>

This is the behavior WCF Data Services implement, and it's required for third party OData client libraries like breeze.js to work against Web API OData properly.

Work Item Details

Original CodePlex Issue: Issue 1094 Status: Active Reason Closed: Unassigned Assigned to: xuzhg Reported on: Jun 18, 2013 at 11:54 PM Reported by: jacalvar Updated on: Dec 24, 2014 at 6:08 AM Updated by: xuzhg

LianwMS commented 9 years ago

On 2013-08-15 03:33:19 UTC, meirb commented:

Will this be fixed for vNext when working with the odata model builder?

xuzhg commented 9 years ago

Resolved: 9506374fb5a7471de47f765b6e9a240e0a542b13