Updates Castle to the latest NHibernate Trunk libs. This required namespace changes...
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / NestedAttribute.cs
bloba9a9ab20d1f5db2b74932b16365165826382c0e3
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 /// Maps properties of a child object to columns of the table
21 /// of a parent class.
22 /// </summary>
23 /// <example>
24 /// The following code illustrates the use of a
25 /// nested <c>PostalAddress</c> class
26 /// <code>
27 /// [ActiveRecord("Companies")]
28 /// public class Company : ActiveRecordBase
29 /// {
30 /// private int id;
31 /// private PostalAddress _address;
32 ///
33 /// public Company()
34 /// {
35 /// }
36 ///
37 /// public Company(string name)
38 /// {
39 /// this.name = name;
40 /// }
41 ///
42 /// [PrimaryKey]
43 /// public int Id
44 /// {
45 /// get { return id; }
46 /// set { id = value; }
47 /// }
48 ///
49 /// [Nested]
50 /// public PostalAddress Address
51 /// {
52 /// get { return _address; }
53 /// set { _address = value; }
54 /// }
55 /// }
56 ///
57 /// public class PostalAddress
58 /// {
59 /// private String _address;
60 /// private String _city;
61 /// private String _state;
62 /// private String _zipcode;
63 ///
64 /// [Property]
65 /// public String Address
66 /// {
67 /// get { return _address; }
68 /// set { _address = value; }
69 /// }
70 ///
71 /// [Property]
72 /// public String City
73 /// {
74 /// get { return _city; }
75 /// set { _city = value;}
76 /// }
77 ///
78 /// [Property]
79 /// public String State
80 /// {
81 /// get { return _state; }
82 /// set { _state = value; }
83 /// }
84 ///
85 /// [Property]
86 /// public String ZipCode
87 /// {
88 /// get { return _zipcode; }
89 /// set { _zipcode = value; }
90 /// }
91 /// }
92 /// </code>
93 /// </example>
94 [AttributeUsage(AttributeTargets.Property, AllowMultiple=false), Serializable]
95 public class NestedAttribute : WithAccessAttribute
97 private bool update = true;
98 private bool insert = true;
99 private Type mapType;
100 private String columnPrefix;
102 /// <summary>
103 /// Informs ActiveRecord that the marked property contains nested elements, contained
104 /// in a separate, reusable class.
105 /// </summary>
106 public NestedAttribute() {}
108 /// <summary>
109 /// Informs ActiveRecord that the marked property contains nested elements, contained
110 /// in a separate, reusable class.
111 /// </summary>
112 /// <param name="columnPrefix">A prefix to insert before each column in the nested component</param>
113 public NestedAttribute(String columnPrefix)
115 this.columnPrefix = columnPrefix;
118 /// <summary>
119 /// Allows one to reference a different type
120 /// than the property type
121 /// </summary>
122 public Type MapType
124 get { return mapType; }
125 set { mapType = value; }
128 /// <summary>
129 /// Set to <c>false</c> to ignore this nested component when updating entities of this ActiveRecord class.
130 /// </summary>
131 public bool Update
133 get { return update; }
134 set { update = value; }
137 /// <summary>
138 /// Set to <c>false</c> to ignore this nested component when inserting entities of this ActiveRecord class.
139 /// </summary>
140 public bool Insert
142 get { return insert; }
143 set { insert = value; }
146 /// <summary>
147 /// A prefix to insert before each column in the nested component.
148 /// </summary>
149 public String ColumnPrefix
151 get { return this.columnPrefix; }
152 set { this.columnPrefix = value; }