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 /// This attribute allows polymorphic association between classes that doesn't have a common root class.
21 /// In require two columns that would tell it what is the type of the asssoicated entity, and what is the PK of that entity.
23 /// This is supplied for advanced sceanrios.
26 /// For instnace, let assume that you have two classes (that implement a common interface, but have no base classs) called:
30 /// And you have a set of Payment methods, that can be either. You would define the mapping so:
32 /// [HasManyToAny(typeof(IPayment), "pay_id", "payments_table", typeof(int), "payment_type", "payment_method_id",
33 /// MetaType = typeof(int), RelationType = RelationType.Set)]
35 /// typeof(IPayement) - the common interface tha both classes implement, and the type of all the items in the set.
36 /// "pay_id" - the column that hold the PK of this entity (the FK column)
37 /// "payments_table" - the table that has the assoication information (in 1:M scenarios - usuaully the same table, in M:N scenarios the link table).
38 /// typeof(int) - the type of id column
39 /// "payment_type" - the column used to find out which class is represented by this row.
40 /// "payment_method_id" - the column that holds the PK of the assoicated class (either CreditCard or BankAccount).
41 /// MetaType = typeof(int) - the type of the meta column (payment_type)
42 /// RelationType = RelationType.Set - specify that we use a set here
46 [AttributeUsage(AttributeTargets
.Property
), Serializable
]
47 public class HasManyToAnyAttribute
: HasManyAttribute
49 private Type idType
, metaType
;
50 private string idColumn
, typeColumn
;
53 /// Initializes a new instance of the <see cref="HasManyToAnyAttribute"/> class.
55 /// <param name="mapType">Type of the map.</param>
56 /// <param name="keyColum">The key colum.</param>
57 /// <param name="table">The table.</param>
58 /// <param name="idType">Type of the id.</param>
59 /// <param name="typeColumn">The type column.</param>
60 /// <param name="idColumn">The id column.</param>
61 public HasManyToAnyAttribute(Type mapType
, string keyColum
,
62 string table
, Type idType
,
63 string typeColumn
, string idColumn
) : base(mapType
, keyColum
, table
)
66 this.typeColumn
= typeColumn
;
67 this.idColumn
= idColumn
;
71 /// Gets or sets the type column.
73 /// <value>The type column.</value>
74 public string TypeColumn
76 get { return typeColumn; }
77 set { typeColumn = value; }
81 /// Gets or sets the id column.
83 /// <value>The id column.</value>
84 public string IdColumn
86 get { return idColumn; }
87 set { idColumn = value; }
91 /// Gets or sets the type of the meta column
93 /// <value>The type of the meta.</value>
96 get { return metaType; }
97 set { metaType = value; }
101 /// Gets or sets the type of the id column
103 /// <value>The type of the id.</value>
106 get { return idType; }
107 set { idType = value; }