Child pages
  • Bidirectional 1-1 relation
Skip to end of metadata
Go to start of metadata

The bidirectional relationship between a Person and its PhoneNumbers clearly is an 1:m relationship, as indicated by the PhoneNumbers property's type – ObjectList<PhoneNumber>. Bidirectional 1:1 relationships are declared more or less in the same way, with one important difference. You must specify which of the two ends , or tables, holds the foreign key. Here is a 1:1 relationship between a company and its president. Note the ContainsKey parameter in the Company's [ DBBidirectionalRelation ] attribute:

public class Company : DomainObject 
{
  // The 'Company' table will hold the foreign key
  [DBBidirectionalRelation ("PresidentOf", ContainsKey = true)]
  [Mandatory]
  public virtual Person President { get; set; } 
} 

public class Person : DomainObject 
{
  [DBBidirectionalRelation ("President")]
  [Mandatory]
  public virtual Company PresidentOf { get; set; } 
}
  • No labels