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 /// Maps a standard column of the table.
23 /// In the following example, the column is also
24 /// called 'name', so you don't have to specify.
26 /// public class Blog : ActiveRecordBase
34 [AttributeUsage(AttributeTargets
.Field
), Serializable
]
35 public class FieldAttribute
: WithAccessAttribute
37 private String column
;
38 private String formula
;
40 private String uniqueKey
;
42 private String sqlType
;
47 private bool update
= true;
48 private bool insert
= true;
51 /// Initializes a new instance of the <see cref="FieldAttribute"/> class.
53 public FieldAttribute()
55 Access
= PropertyAccess
.Field
;
59 /// Initializes a new instance of the <see cref="FieldAttribute"/> class.
61 /// <param name="column">The column name.</param>
62 public FieldAttribute(String column
) : this()
68 /// Initializes a new instance of the <see cref="FieldAttribute"/> class.
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
)
78 /// Gets or sets a value indicating whether the column allows null values
80 /// <value><c>true</c> if [not null]; otherwise, <c>false</c>.</value>
83 get { return notNull; }
84 set { notNull = value; }
88 /// Gets or sets the length of this column. char(10), etc
90 /// <value>The length.</value>
93 get { return length; }
94 set { length = value; }
98 /// Gets or sets the column name
100 /// <value>The column.</value>
103 get { return column; }
104 set { column = value; }
108 /// From NHibernate documentation:
109 /// A unique-key attribute can be used to group columns
110 /// in a single unit key constraint.
112 /// <value>unique key name</value>
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.
119 public string UniqueKey
121 get { return uniqueKey; }
122 set { uniqueKey = value; }
126 /// From NHibernate documentation:
127 /// specifies the name of a (multi-column) index
129 /// <value>index name</value>
132 get { return index; }
133 set { index = value; }
137 /// From NHibernate documentation:
138 /// overrides the default column type
140 /// <value>column_type</value>
141 public string SqlType
143 get { return sqlType; }
144 set { sqlType = value; }
148 /// From NHibernate documentation:
149 /// create an SQL check constraint on either column or table
151 /// <value>Sql Expression</value>
154 get { return check; }
155 set { check = value; }
159 /// Set to <c>false</c> to ignore this
160 /// field when updating entities of this ActiveRecord class.
164 get { return update; }
165 set { update = value; }
169 /// Set to <c>false</c> to ignore this
170 /// field when inserting entities of this ActiveRecord class.
174 get { return insert; }
175 set { insert = value; }
179 /// Gets or sets a value indicating whether this <see cref="FieldAttribute"/> is unique.
181 /// <value><c>true</c> if unique; otherwise, <c>false</c>.</value>
184 get { return unique; }
185 set { unique = value; }
189 /// Gets or sets the formula used to calculate this field
191 /// <value>The formula.</value>
192 public String Formula
194 get { return formula; }
195 set { formula = value; }
199 /// Gets or sets the type of the column.
201 /// <value>The type of the column.</value>
202 public String ColumnType
205 set { type = value; }