IT:AD:Code First:FluentAPI:Relationships

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; }
}
  • /home/skysigal/public_html/data/pages/it/ad/code_first/fluentapi/relationships/home.txt
  • Last modified: 2023/11/04 02:19
  • by 127.0.0.1