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
18 using Castle
.ActiveRecord
.Framework
.Internal
;
21 /// Define the relation type for a relation.
24 public enum RelationType
27 /// Let Active Record guess what is the type of the relation.
31 /// An bag of items (allow duplicates)
35 /// A set of unique items
39 /// A bag of items with id
43 /// Map of key/value pairs (IDictionary)
47 /// A list of items - position in the list has meaning
53 /// Base class to define common relation information
55 [AttributeUsage(AttributeTargets
.Property
), Serializable
]
56 public abstract class RelationAttribute
: BaseAttribute
58 internal Type mapType
;
59 internal String table
;
60 internal String schema
;
61 internal String orderBy
;
62 internal String where
;
64 internal String index
;
65 internal String indexType
;
66 internal String element
, elementType
;
68 internal bool lazySpecified
= false;
69 internal bool inverse
;
70 internal ManyRelationCascadeEnum cascade
= ManyRelationCascadeEnum
.None
;
71 internal RelationType relType
= RelationType
.Guess
;
72 internal NotFoundBehaviour notFoundBehaviour
= NotFoundBehaviour
.Default
;
73 private int batchSize
= 1;
76 /// Gets or sets the type of the relation.
78 /// <value>The type of the relation.</value>
79 public RelationType RelationType
81 get { return relType; }
82 set { relType = value; }
86 /// Gets or sets the type of the map.
88 /// <value>The type of the map.</value>
91 get { return mapType; }
92 set { mapType = value; }
96 /// Gets or sets the table for this relation
98 /// <value>The table.</value>
101 get { return table; }
102 set { table = value; }
106 /// Gets or sets the schema for this relation (dbo., etc)
108 /// <value>The schema name.</value>
111 get { return schema; }
112 set { schema = value; }
116 /// Gets or sets a value indicating whether this <see cref="RelationAttribute"/> is lazy.
118 /// <value><c>true</c> if lazy; otherwise, <c>false</c>.</value>
125 return ActiveRecordModel
.isLazyByDefault
;
130 lazySpecified
= true;
135 /// Gets or sets a value indicating whether this <see cref="RelationAttribute"/> is inverse.
137 /// <value><c>true</c> if inverse; otherwise, <c>false</c>.</value>
140 get { return inverse; }
141 set { inverse = value; }
145 /// Gets or sets the cascade options for this <see cref="RelationAttribute"/>
147 /// <value>The cascade.</value>
148 public ManyRelationCascadeEnum Cascade
150 get { return cascade; }
151 set { cascade = value; }
155 /// Gets or sets the order by clause for this relation. This is a SQL order, not HQL.
157 public String OrderBy
159 get { return orderBy; }
160 set { orderBy = value; }
164 /// Gets or sets the where clause for this relation
168 get { return where; }
169 set { where = value; }
173 /// Only used with sets. The value can be <c>unsorted</c>, <c>natural</c> and the name of a class implementing <c>System.Collections.IComparer</c>
178 set { sort = value; }
182 /// Only used with maps or lists
186 get { return index; }
187 set { index = value; }
191 /// Only used with maps
193 public string IndexType
195 get { return indexType; }
196 set { indexType = value; }
200 /// Use for simple types.
202 public string Element
204 get { return element; }
205 set { element = value; }
209 /// Use for simple types.
211 public string ElementType
213 get { return elementType; }
214 set { elementType = value; }
218 /// Gets or sets the way broken relations are handled.
220 /// <value>The behaviour.</value>
221 public NotFoundBehaviour NotFoundBehaviour
223 get { return notFoundBehaviour; }
224 set { notFoundBehaviour = value; }
228 /// From NHibernate documentation:
229 /// Specify a "batch size" for batch fetching of collections.
233 get { return batchSize; }
234 set { batchSize = value; }