This workitem tracks the remaining work of https://aspnetwebstack.codeplex.com/workitem/1423 as the changes in the model builder required to support referential constraints and AssociationLinkAttribute are out of scope of the bug.
Basically we currently build the model in the following way:
We build the type headers.
We build the properties (navigation and structural at the same time)
In order to support adding referential constraints we should build the model the following way:
Build the type headers.
Build the structural properties for all types.
Build the navigation properties for all types.
It will require extending the default ODataModelBuilder to allow specifying principal and dependent properties of the relationship, and a convention on the ODataConventionModelBuilder to support AssociationAttribute, for example
```
public class Customer
{
public int Id { get; set; }
public ICollection<Order> { get; set;}
}
public class Order
{
public int Id { get; set; }
public int CustomerId { get; set; }
[Association(IsForeignKey=true, ThisKey="CustomerId", OtherKey="Id")]
public Customer { get; set; }
}
```
Would result in a navigation property being created for the given entity that specifies the referential constraint in the $metadata
Basically we currently build the model in the following way:
We build the type headers.
We build the properties (navigation and structural at the same time)
In order to support adding referential constraints we should build the model the following way:
Build the type headers.
Build the structural properties for all types.
Build the navigation properties for all types.
It will require extending the default ODataModelBuilder to allow specifying principal and dependent properties of the relationship, and a convention on the ODataConventionModelBuilder to support AssociationAttribute, for example
```
public class Customer
{
public int Id { get; set; }
public ICollection<Order> { get; set;}
}
public class Order
{
public int Id { get; set; }
public int CustomerId { get; set; }
[Association(IsForeignKey=true, ThisKey="CustomerId", OtherKey="Id")]
public Customer { get; set; }
}
```
Would result in a navigation property being created for the given entity that specifies the referential constraint in the $metadata