1 // Copyright 2004-2007 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
;
111 /// Allows one to reference a different type
112 /// than the property type
116 get { return mapType; }
117 set { mapType = value; }
121 /// From NHibernate docs: specifies which operations should be
122 /// cascaded from the parent object to the associated object.
124 public CascadeEnum Cascade
126 get { return cascade; }
127 set { cascade = value; }
131 /// From NHibernate docs: Chooses between outer-join fetching
132 /// or sequential select fetching.
135 /// Defaults to <see cref="FetchEnum.Select"/>
137 public FetchEnum Fetch
139 get { return fetch; }
140 set { fetch = value; }
144 /// From NHibernate docs: The name of a property of the
145 /// associated class that is joined to the primary key
146 /// of this class. If not specified, the primary key of
147 /// the associated class is used.
149 public string PropertyRef
151 get { return propertyRef; }
152 set { propertyRef = value; }
156 /// From NHibernate docs: specifies that a foreign key
157 /// constraint on the primary key of the mapped table
158 /// references the table of the associated class.
159 /// This option affects the order in which Save() and
160 /// Delete() are cascaded (and is also used by the
161 /// schema export tool).
163 public bool Constrained
165 get { return constrained; }
166 set { constrained = value; }