Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / FieldAttribute.cs
blob3ca4d3c1cfe9666c6e80348e98860a670bcefa1d
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 /// [Field]
29 /// string name;
30 ///
31 ///
32 /// </code>
33 /// </example>
34 [AttributeUsage(AttributeTargets.Field), Serializable]
35 public class FieldAttribute : WithAccessAttribute
37 private String column;
38 private String formula;
39 private String type;
40 private String uniqueKey;
41 private String index;
42 private String sqlType;
43 private String check;
44 private int length;
45 private bool notNull;
46 private bool unique;
47 private bool update = true;
48 private bool insert = true;
50 /// <summary>
51 /// Initializes a new instance of the <see cref="FieldAttribute"/> class.
52 /// </summary>
53 public FieldAttribute()
55 Access = PropertyAccess.Field;
58 /// <summary>
59 /// Initializes a new instance of the <see cref="FieldAttribute"/> class.
60 /// </summary>
61 /// <param name="column">The column name.</param>
62 public FieldAttribute(String column) : this()
64 this.column = column;
67 /// <summary>
68 /// Initializes a new instance of the <see cref="FieldAttribute"/> class.
69 /// </summary>
70 /// <param name="column">The column name</param>
71 /// <param name="type">The column type.</param>
72 public FieldAttribute(String column, String type) : this(column)
74 this.type = type;
77 /// <summary>
78 /// Gets or sets a value indicating whether the column allows null values
79 /// </summary>
80 /// <value><c>true</c> if [not null]; otherwise, <c>false</c>.</value>
81 public bool NotNull
83 get { return notNull; }
84 set { notNull = value; }
87 /// <summary>
88 /// Gets or sets the length of this column. char(10), etc
89 /// </summary>
90 /// <value>The length.</value>
91 public int Length
93 get { return length; }
94 set { length = value; }
97 /// <summary>
98 /// Gets or sets the column name
99 /// </summary>
100 /// <value>The column.</value>
101 public String Column
103 get { return column; }
104 set { column = value; }
107 /// <summary>
108 /// From NHibernate documentation:
109 /// A unique-key attribute can be used to group columns
110 /// in a single unit key constraint.
111 /// </summary>
112 /// <value>unique key name</value>
113 /// <remarks>
114 /// Currently, the
115 /// specified value of the unique-key attribute is not
116 /// used to name the constraint, only to group the columns
117 /// in the mapping file.
118 /// </remarks>
119 public string UniqueKey
121 get { return uniqueKey; }
122 set { uniqueKey = value; }
125 /// <summary>
126 /// From NHibernate documentation:
127 /// specifies the name of a (multi-column) index
128 /// </summary>
129 /// <value>index name</value>
130 public string Index
132 get { return index; }
133 set { index = value; }
136 /// <summary>
137 /// From NHibernate documentation:
138 /// overrides the default column type
139 /// </summary>
140 /// <value>column_type</value>
141 public string SqlType
143 get { return sqlType; }
144 set { sqlType = value; }
147 /// <summary>
148 /// From NHibernate documentation:
149 /// create an SQL check constraint on either column or table
150 /// </summary>
151 /// <value>Sql Expression</value>
152 public string Check
154 get { return check; }
155 set { check = value; }
158 /// <summary>
159 /// Set to <c>false</c> to ignore this
160 /// field when updating entities of this ActiveRecord class.
161 /// </summary>
162 public bool Update
164 get { return update; }
165 set { update = value; }
168 /// <summary>
169 /// Set to <c>false</c> to ignore this
170 /// field when inserting entities of this ActiveRecord class.
171 /// </summary>
172 public bool Insert
174 get { return insert; }
175 set { insert = value; }
178 /// <summary>
179 /// Gets or sets a value indicating whether this <see cref="FieldAttribute"/> is unique.
180 /// </summary>
181 /// <value><c>true</c> if unique; otherwise, <c>false</c>.</value>
182 public bool Unique
184 get { return unique; }
185 set { unique = value; }
188 /// <summary>
189 /// Gets or sets the formula used to calculate this field
190 /// </summary>
191 /// <value>The formula.</value>
192 public String Formula
194 get { return formula; }
195 set { formula = value; }
198 /// <summary>
199 /// Gets or sets the type of the column.
200 /// </summary>
201 /// <value>The type of the column.</value>
202 public String ColumnType
204 get { return type; }
205 set { type = value; }