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 many to many association with an association table.
23 /// public class Company : ActiveRecordBase
27 /// [HasAndBelongsToMany( typeof(Person), RelationType.Bag, Table="PeopleCompanies", Column="person_id", ColumnKey="company_id" )]
28 /// public IList People
30 /// get { return _people; }
31 /// set { _people = value; }
35 /// <remarks>The <see cref="ColumnKey"/> must specify the key on the
36 /// association table that points to the primary key of this class. In
37 /// the example, 'company_id' points to 'Company'.
39 [AttributeUsage(AttributeTargets
.Property
, AllowMultiple
=false), Serializable
]
40 public class HasAndBelongsToManyAttribute
: RelationAttribute
42 private String columnRef
;
43 private String
[] compositeKeyColumnRefs
;
44 private String columnKey
;
45 private String
[] compositeKeyColumnKeys
;
46 private FetchEnum fetchMethod
= FetchEnum
.Unspecified
;
47 private Type customCollectionType
;
50 /// Initializes a new instance of the <see cref="HasAndBelongsToManyAttribute"/> class.
52 /// <param name="mapType">Type of the map.</param>
53 public HasAndBelongsToManyAttribute( Type mapType
)
55 this.mapType
= mapType
;
60 /// Initializes a new instance of the <see cref="HasAndBelongsToManyAttribute"/> class.
62 public HasAndBelongsToManyAttribute()
67 /// Initializes a new instance of the <see cref="HasAndBelongsToManyAttribute"/> class.
69 /// <param name="mapType">Type of the map.</param>
70 /// <param name="type">The type.</param>
71 public HasAndBelongsToManyAttribute( Type mapType
, RelationType type
) : this(mapType
)
77 /// Gets or sets the column that represent the other side on the assoication table
79 /// <value>The column ref.</value>
80 public String ColumnRef
82 get { return columnRef; }
83 set { columnRef = value; }
87 /// Gets or sets the composite key columns that represent the other side on the assoication table
89 /// <value>The composite key column refs.</value>
90 public String
[] CompositeKeyColumnRefs
92 get { return compositeKeyColumnRefs; }
93 set { compositeKeyColumnRefs = value; }
97 /// Gets or sets the key column name
99 /// <value>The column key.</value>
100 public String ColumnKey
102 get { return columnKey; }
103 set { columnKey = value; }
107 /// Gets or sets the composite key columns names.
109 /// <value>The composite key column keys.</value>
110 public String
[] CompositeKeyColumnKeys
112 get { return compositeKeyColumnKeys; }
113 set { compositeKeyColumnKeys = value; }
117 /// Chooses between outer-join fetching
118 /// or sequential select fetching.
120 public FetchEnum Fetch
122 get { return fetchMethod; }
123 set { fetchMethod = value; }
127 /// Provides a custom collection type.
129 public Type CollectionType
131 get { return customCollectionType; }
132 set { customCollectionType = value; }