1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
20 /// Associates a foreign table where the current class
21 /// and the target class share their primary key.
24 /// The following code exemplifies two classes that maps
25 /// to two tables sharing the primary key:
27 /// [ActiveRecord("Employee")]
28 /// public class Employee : ActiveRecordBase
31 /// private Award award;
33 /// [PrimaryKey(PrimaryKeyType.Native, "EmployeeID")]
36 /// get { return this.id; }
37 /// set { this.id = value; }
41 /// public Award Award
43 /// get { return this.award; }
44 /// set { this.award = value; }
48 /// [ActiveRecord("Award")]
49 /// public class Award : ActiveRecordBase
51 /// private Employee employee;
58 /// public Award(Employee employee)
60 /// this.employee = employee;
64 /// public Employee Employee
66 /// get { return this.employee; }
67 /// set { this.employee = value; }
70 /// [PrimaryKey(PrimaryKeyType.Foreign, "EmployeeID")]
73 /// get { return this.id; }
74 /// set { this.id = value; }
77 /// public static Award[] FindAll()
79 /// return ((Award[]) (ActiveRecordBase.FindAll(typeof(Award))));
82 /// public static void DeleteAll()
84 /// ActiveRecordBase.DeleteAll( typeof(Award) );
87 /// Employee emp = new Employee();
88 /// emp.Name = "john doe";
91 /// Award award = new Award(emp);
92 /// award.Description = "Invisible employee";
97 /// Usually classes that uses the primary key
98 /// generated elsewhere (foreign) uses the PrimaryKey attribute with the
99 /// generator type <c>PrimaryKeyType.Foreign</c>
101 [AttributeUsage(AttributeTargets
.Property
, AllowMultiple
=false), Serializable
]
102 public class OneToOneAttribute
: WithAccessAttribute
104 private CascadeEnum cascade
= CascadeEnum
.None
;
105 private FetchEnum fetch
= FetchEnum
.Unspecified
;
106 private String propertyRef
;
107 private Type mapType
;
108 private bool constrained
;
109 private string foreignKey
;
112 /// Allows one to reference a different type
113 /// than the property type
117 get { return mapType; }
118 set { mapType = value; }
122 /// From NHibernate docs: specifies which operations should be
123 /// cascaded from the parent object to the associated object.
125 public CascadeEnum Cascade
127 get { return cascade; }
128 set { cascade = value; }
132 /// From NHibernate docs: Chooses between outer-join fetching
133 /// or sequential select fetching.
136 /// Defaults to <see cref="FetchEnum.Select"/>
138 public FetchEnum Fetch
140 get { return fetch; }
141 set { fetch = value; }
145 /// From NHibernate docs: The name of a property of the
146 /// associated class that is joined to the primary key
147 /// of this class. If not specified, the primary key of
148 /// the associated class is used.
150 public string PropertyRef
152 get { return propertyRef; }
153 set { propertyRef = value; }
157 /// From NHibernate docs: specifies that a foreign key
158 /// constraint on the primary key of the mapped table
159 /// references the table of the associated class.
160 /// This option affects the order in which Save() and
161 /// Delete() are cascaded (and is also used by the
162 /// schema export tool).
164 public bool Constrained
166 get { return constrained; }
167 set { constrained = value; }
171 /// Gets or sets the name of the foreign key constraint generated for
172 /// an association. NHibernate will only use the ForeignKey name one
173 /// the inherited class and Constrained = true.
175 public string ForeignKey
177 get { return foreignKey; }
178 set { foreignKey = value; }