Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / PropertyAttribute.cs
blobcebdeb298de6313e1a861210fe253c5c19159e05
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 a standard column of the table.
21 /// </summary>
22 /// <example>
23 /// In the following example, the column is also
24 /// called 'name', so you don't have to specify.
25 /// <code>
26 /// public class Blog : ActiveRecordBase
27 /// {
28 /// ...
29 ///
30 /// [Property]
31 /// public int Name
32 /// {
33 /// get { return _name; }
34 /// set { _name = value; }
35 /// }
36 /// </code>
37 /// To map a column name, use
38 /// <code>
39 /// [Property("blog_name")]
40 /// public int Name
41 /// {
42 /// get { return _name; }
43 /// set { _name = value; }
44 /// }
45 /// </code>
46 /// </example>
47 [AttributeUsage(AttributeTargets.Property), Serializable]
48 public class PropertyAttribute : WithAccessAttribute
50 private String column;
51 private String formula;
52 private String type;
53 private String uniqueKey;
54 private String index;
55 private String sqlType;
56 private String check;
57 private int length;
58 private bool notNull;
59 private bool unique;
60 private bool update = true;
61 private bool insert = true;
62 private bool isOverride;
64 /// <summary>
65 /// Initializes a new instance of the <see cref="PropertyAttribute"/> class.
66 /// </summary>
67 public PropertyAttribute()
71 /// <summary>
72 /// Initializes a new instance of the <see cref="PropertyAttribute"/> class.
73 /// </summary>
74 /// <param name="column">The column.</param>
75 public PropertyAttribute(String column) : this()
77 this.column = column;
80 /// <summary>
81 /// Initializes a new instance of the <see cref="PropertyAttribute"/> class.
82 /// </summary>
83 /// <param name="column">The column.</param>
84 /// <param name="type">The type.</param>
85 public PropertyAttribute(String column, String type) : this(column)
87 this.type = type;
90 /// <summary>
91 /// Gets or sets a value indicating whether this property allow null.
92 /// </summary>
93 /// <value><c>true</c> if allow null; otherwise, <c>false</c>.</value>
94 public bool NotNull
96 get { return notNull; }
97 set { notNull = value; }
100 /// <summary>
101 /// Gets or sets the length of the property (for strings - nvarchar(50) )
102 /// </summary>
103 /// <value>The length.</value>
104 public int Length
106 get { return length; }
107 set { length = value; }
110 /// <summary>
111 /// Gets or sets the column name
112 /// </summary>
113 /// <value>The column.</value>
114 public String Column
116 get { return column; }
117 set { column = value; }
120 /// <summary>
121 /// Set to <c>false</c> to ignore this property when updating entities of this ActiveRecord class.
122 /// </summary>
123 public bool Update
125 get { return update; }
126 set { update = value; }
129 /// <summary>
130 /// Set to <c>false</c> to ignore this property when inserting entities of this ActiveRecord class.
131 /// </summary>
132 public bool Insert
134 get { return insert; }
135 set { insert = value; }
138 /// <summary>
139 /// Gets or sets a value indicating whether this <see cref="PropertyAttribute"/> is unique.
140 /// </summary>
141 /// <value><c>true</c> if unique; otherwise, <c>false</c>.</value>
142 public bool Unique
144 get { return unique; }
145 set { unique = value; }
148 /// <summary>
149 /// Gets or sets the formula used to calculate this property
150 /// </summary>
151 /// <value>The formula.</value>
152 public String Formula
154 get { return formula; }
155 set { formula = value; }
158 /// <summary>
159 /// Gets or sets the type of the column.
160 /// </summary>
161 /// <value>The type of the column.</value>
162 public String ColumnType
164 get { return type; }
165 set { type = value; }
168 /// <summary>
169 /// From NHibernate documentation:
170 /// A unique-key attribute can be used to group columns
171 /// in a single unit key constraint.
172 /// </summary>
173 /// <value>unique key name</value>
174 /// <remarks>
175 /// Currently, the
176 /// specified value of the unique-key attribute is not
177 /// used to name the constraint, only to group the columns
178 /// in the mapping file.
179 /// </remarks>
180 public string UniqueKey
182 get { return uniqueKey; }
183 set { uniqueKey = value; }
186 /// <summary>
187 /// From NHibernate documentation:
188 /// specifies the name of a (multi-column) index
189 /// </summary>
190 /// <value>index name</value>
191 public string Index
193 get { return index; }
194 set { index = value; }
197 /// <summary>
198 /// From NHibernate documentation:
199 /// overrides the default column type
200 /// </summary>
201 /// <value>column_type</value>
202 public string SqlType
204 get { return sqlType; }
205 set { sqlType = value; }
208 /// <summary>
209 /// From NHibernate documentation:
210 /// create an SQL check constraint on either column or table
211 /// </summary>
212 /// <value>Sql Expression</value>
213 public string Check
215 get { return check; }
216 set { check = value; }
219 /// <summary>
220 /// Set to <c>true</c> if this property overrides a property in a base class
221 /// </summary>
222 public bool IsOverride
224 get { return isOverride; }
225 set { isOverride = value; }