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>
<EntityType Name="ProductFamily">
<NavigationProperty Name="Products" Relationship="ODataService.Models.ODataService_Models_ProductFamily_Products_ODataService_Models_Product_ProductsPartner" ToRole="Products" FromRole="ProductsPartner" />
</EntityType>
<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>
<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" />
</Association>
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>
<EntityType Name="Category">
<NavigationProperty Name="Products" Relationship="ODataDemo.Product_Category_Category_Products" FromRole="Category_Products" ToRole="Product_Category" />
</EntityType>
<Association Name="Product_Category_Category_Products">
<End Role="Product_Category" Type="ODataDemo.Product" Multiplicity="*" />
<End Role="Category_Products" Type="ODataDemo.Category" Multiplicity="0..1" />
</Association>
The issue happens in both convention and explicit model builder.
Comments: I have just verified this with WCF DS and WCF DS seems to do the other thing i.e generating only one Association.
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>
<EntityType Name="ProductFamily">
<NavigationProperty Name="Products" Relationship="ODataService.Models.ODataService_Models_ProductFamily_Products_ODataService_Models_Product_ProductsPartner" ToRole="Products" FromRole="ProductsPartner" />
</EntityType>
<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>
<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" />
</Association>
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>
<EntityType Name="Category">
<NavigationProperty Name="Products" Relationship="ODataDemo.Product_Category_Category_Products" FromRole="Category_Products" ToRole="Product_Category" />
</EntityType>
<Association Name="Product_Category_Category_Products">
<End Role="Product_Category" Type="ODataDemo.Product" Multiplicity="*" />
<End Role="Category_Products" Type="ODataDemo.Category" Multiplicity="0..1" />
</Association>
The issue happens in both convention and explicit model builder.
Comments: I have just verified this with WCF DS and WCF DS seems to do the other thing i.e generating only one Association.