Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / HasManyToAnyAttribute.cs
blob4c04741b0bc68f213390b94700f3fa17b3aa40e5
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
19 /// <summary>
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.
22 /// <remarks>
23 /// This is supplied for advanced sceanrios.
24 /// </remarks>
25 /// <example>
26 /// For instnace, let assume that you have two classes (that implement a common interface, but have no base classs) called:
27 /// - Back Account
28 /// - Credit Card
29 ///
30 /// And you have a set of Payment methods, that can be either. You would define the mapping so:
31 /// <code>
32 /// [HasManyToAny(typeof(IPayment), "pay_id", "payments_table", typeof(int), "payment_type", "payment_method_id",
33 /// MetaType = typeof(int), RelationType = RelationType.Set)]
34 /// </code>
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
43 /// </example>
44 ///
45 /// </summary>
46 [AttributeUsage(AttributeTargets.Property), Serializable]
47 public class HasManyToAnyAttribute : HasManyAttribute
49 private Type idType, metaType;
50 private string idColumn, typeColumn;
52 /// <summary>
53 /// Initializes a new instance of the <see cref="HasManyToAnyAttribute"/> class.
54 /// </summary>
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)
65 this.idType = idType;
66 this.typeColumn = typeColumn;
67 this.idColumn = idColumn;
70 /// <summary>
71 /// Gets or sets the type column.
72 /// </summary>
73 /// <value>The type column.</value>
74 public string TypeColumn
76 get { return typeColumn; }
77 set { typeColumn = value; }
80 /// <summary>
81 /// Gets or sets the id column.
82 /// </summary>
83 /// <value>The id column.</value>
84 public string IdColumn
86 get { return idColumn; }
87 set { idColumn = value; }
90 /// <summary>
91 /// Gets or sets the type of the meta column
92 /// </summary>
93 /// <value>The type of the meta.</value>
94 public Type MetaType
96 get { return metaType; }
97 set { metaType = value; }
100 /// <summary>
101 /// Gets or sets the type of the id column
102 /// </summary>
103 /// <value>The type of the id.</value>
104 public Type IdType
106 get { return idType; }
107 set { idType = value; }