Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

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