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 /// Maps a one to many association.
23 /// public class Blog : ActiveRecordBase
27 /// [HasMany(typeof(Post), RelationType.Bag, ColumnKey="Posts", Table="Posts")]
28 /// public IList Posts
30 /// get { return _posts; }
31 /// set { _posts = value; }
34 [AttributeUsage(AttributeTargets
.Property
), Serializable
]
35 public class HasManyAttribute
: RelationAttribute
39 /// Cannot exist if compositeKeyColumns has a value
41 protected String keyColumn
;
43 /// The composite columns
44 /// Cannot exist with keyColumn != null
46 protected String
[] compositeKeyColumns
;
49 /// Whether the target type is for dependent objects or not
51 protected bool hasDependentObjects
;
54 /// Whether we do outer join fetching for this collection
56 protected FetchEnum fetchMethod
= FetchEnum
.Unspecified
;
59 /// Provides a custom collection type.
61 protected Type customCollectionType
;
64 /// Initializes a new instance of the <see cref="HasManyAttribute"/> class.
66 public HasManyAttribute()
72 /// Initializes a new instance of the <see cref="HasManyAttribute"/> class.
74 /// <param name="mapType">Type of the map.</param>
75 public HasManyAttribute(Type mapType
)
77 base.mapType
= mapType
;
81 /// Initializes a new instance of the <see cref="HasManyAttribute"/> class.
83 /// <param name="mapType">Type of items in this association</param>
84 /// <param name="keyColumn">The key column.</param>
85 /// <param name="table">The table.</param>
86 public HasManyAttribute(Type mapType
, String keyColumn
, String table
)
88 this.keyColumn
= keyColumn
;
89 base.mapType
= mapType
;
94 /// Gets or sets the key column name.
96 /// <value>The column key.</value>
97 public String ColumnKey
99 get { return keyColumn; }
100 set { keyColumn = value; }
104 /// Gets or sets the names of the column in composite key scenarios.
106 /// <value>The composite key column keys.</value>
107 public String
[] CompositeKeyColumnKeys
109 get { return compositeKeyColumns; }
110 set { compositeKeyColumns = value; }
114 /// Whether or not the target type is a dependent object.
116 /// <value>true = the target type is a dependent object</value>
117 public bool DependentObjects
119 get { return hasDependentObjects; }
120 set { hasDependentObjects = value; }
124 /// Chooses between outer-join fetching
125 /// or sequential select fetching.
127 public FetchEnum Fetch
129 get { return fetchMethod; }
130 set { fetchMethod = value; }
134 /// Provides a custom collection type.
136 public Type CollectionType
138 get { return customCollectionType; }
139 set { customCollectionType = value; }