This project is read-only.


OData model builder should reuse association for bi-direction navigation properties


Association should represent a bi-direction relationship of two entities. It doesn't make sense to have two associations for bidirection navigation properties.

For example, in odata service sample, it has model:

public class ProductFamily
public Collection<Product> Products;
public class Product
public ProductFamily Family;

The generated associations are:
  <EntityType Name="Product">
    <NavigationProperty Name="Family" Relationship="ODataService.Models.ODataService_Models_Product_Family_ODataService_Models_ProductFamily_FamilyPartner" ToRole="Family" FromRole="FamilyPartner" />
  <EntityType Name="ProductFamily">
    <NavigationProperty Name="Products" Relationship="ODataService.Models.ODataService_Models_ProductFamily_Products_ODataService_Models_Product_ProductsPartner" ToRole="Products" FromRole="ProductsPartner" />
  <Association Name="ODataService_Models_Product_Family_ODataService_Models_ProductFamily_FamilyPartner">
    <End Type="ODataService.Models.ProductFamily" Role="Family" Multiplicity="0..1" />
    <End Type="ODataService.Models.Product" Role="FamilyPartner" Multiplicity="0..1" />
  <Association Name="ODataService_Models_ProductFamily_Products_ODataService_Models_Product_ProductsPartner">
    <End Type="ODataService.Models.Product" Role="Products" Multiplicity="*" />
    <End Type="ODataService.Models.ProductFamily" Role="ProductsPartner" Multiplicity="0..1" />
The expected behavior should only generate one association that describe product family and product are one to many relationship. Each navigation property reuse the association but switching FromRole and EndRole to represent the association direction.

For example, the odata sample service shows following $metadata with similar models:
  <EntityType Name="Product">
    <NavigationProperty Name="Category" Relationship="ODataDemo.Product_Category_Category_Products" FromRole="Product_Category" ToRole="Category_Products" />
  <EntityType Name="Category">
    <NavigationProperty Name="Products" Relationship="ODataDemo.Product_Category_Category_Products" FromRole="Category_Products" ToRole="Product_Category" />
  <Association Name="Product_Category_Category_Products">
    <End Role="Product_Category" Type="ODataDemo.Product" Multiplicity="*" />
    <End Role="Category_Products" Type="ODataDemo.Category" Multiplicity="0..1" />
The issue happens in both convention and explicit model builder.
Closed Mar 29, 2013 at 11:50 PM by HongmeiG
This is probably trying to make the model builder too smart.


raghuramn wrote Nov 14, 2012 at 11:15 PM

I have just verified this with WCF DS and WCF DS seems to do the other thing i.e generating only one Association.

raghuramn wrote Apr 5, 2013 at 8:42 PM

check out my stackoverflow answer on why decided to won't fix this -