IT:AD:Code First:FluentAPI:Relationships
Summary
Single Reference
Inverse Detection occurs naturally if following conventions are met:
- both types define (only) one (reference to or collection) navigation property to the other.
- if not detected automatically, use FluentAPI to set it up.
Automatically:
public class Invoice
{
public int InvoiceId { get; set; }
...
public InvoiceType InvoiceType { get; set; }
}
public class InvoiceType
{
public int InvoiceTypeId { get; set; }
...
public Invoice Invoice { get; set; }
}
* References:
Simple Collection
public class Invoice
{
public Invoice()
{
//Use constructor to create 0-sized collection:
this.Courses = new List<Course>();
}
....
public virtual ICollection<LineItem> LineItems { get; private set; }
}