Associates a foreign table where the current class
and the target class share their primary key.
Namespace: Castle.ActiveRecord
Assembly: Castle.ActiveRecord (in Castle.ActiveRecord.dll)
Version: 1.0.3.0
Syntax
| C# |
|---|
[SerializableAttribute] [AttributeUsageAttribute(AttributeTargets.Property, AllowMultiple = false)] public class OneToOneAttribute : WithAccessAttribute |
Remarks
Usually classes that uses the primary key
generated elsewhere (foreign) uses the PrimaryKey attribute with the
generator type PrimaryKeyType.Foreign
Examples
The following code exemplifies two classes that maps
to two tables sharing the primary key:
CopyC#
[ActiveRecord("Employee")] public class Employee : ActiveRecordBase { private int id; private Award award; [PrimaryKey(PrimaryKeyType.Native, "EmployeeID")] public int ID { get { return this.id; } set { this.id = value; } } [OneToOne] public Award Award { get { return this.award; } set { this.award = value; } } } [ActiveRecord("Award")] public class Award : ActiveRecordBase { private Employee employee; private int id; public Award() { } public Award(Employee employee) { this.employee = employee; } [OneToOne] public Employee Employee { get { return this.employee; } set { this.employee = value; } } [PrimaryKey(PrimaryKeyType.Foreign, "EmployeeID")] public int ID { get { return this.id; } set { this.id = value; } } public static Award[] FindAll() { return ((Award[]) (ActiveRecordBase.FindAll(typeof(Award)))); } public static void DeleteAll() { ActiveRecordBase.DeleteAll( typeof(Award) ); } } Employee emp = new Employee(); emp.Name = "john doe"; emp.Save(); Award award = new Award(emp); award.Description = "Invisible employee"; award.Save(); |
Inheritance Hierarchy
System..::Object
System..::Attribute
Castle.ActiveRecord..::WithAccessAttribute
Castle.ActiveRecord..::OneToOneAttribute
System..::Attribute
Castle.ActiveRecord..::WithAccessAttribute
Castle.ActiveRecord..::OneToOneAttribute
See Also
OneToOneAttribute Members
Castle.ActiveRecord Namespace