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
33 /// get { return _name; }
34 /// set { _name = value; }
37 /// To map a column name, use
39 /// [Property("blog_name")]
42 /// get { return _name; }
43 /// set { _name = value; }
47 [AttributeUsage(AttributeTargets
.Property
), Serializable
]
48 public class PropertyAttribute
: WithAccessAttribute
50 private String column
;
51 private String formula
;
53 private String uniqueKey
;
55 private String sqlType
;
60 private bool update
= true;
61 private bool insert
= true;
62 private bool isOverride
;
65 /// Initializes a new instance of the <see cref="PropertyAttribute"/> class.
67 public PropertyAttribute()
72 /// Initializes a new instance of the <see cref="PropertyAttribute"/> class.
74 /// <param name="column">The column.</param>
75 public PropertyAttribute(String column
) : this()
81 /// Initializes a new instance of the <see cref="PropertyAttribute"/> class.
83 /// <param name="column">The column.</param>
84 /// <param name="type">The type.</param>
85 public PropertyAttribute(String column
, String type
) : this(column
)
91 /// Gets or sets a value indicating whether this property allow null.
93 /// <value><c>true</c> if allow null; otherwise, <c>false</c>.</value>
96 get { return notNull; }
97 set { notNull = value; }
101 /// Gets or sets the length of the property (for strings - nvarchar(50) )
103 /// <value>The length.</value>
106 get { return length; }
107 set { length = value; }
111 /// Gets or sets the column name
113 /// <value>The column.</value>
116 get { return column; }
117 set { column = value; }
121 /// Set to <c>false</c> to ignore this property when updating entities of this ActiveRecord class.
125 get { return update; }
126 set { update = value; }
130 /// Set to <c>false</c> to ignore this property when inserting entities of this ActiveRecord class.
134 get { return insert; }
135 set { insert = value; }
139 /// Gets or sets a value indicating whether this <see cref="PropertyAttribute"/> is unique.
141 /// <value><c>true</c> if unique; otherwise, <c>false</c>.</value>
144 get { return unique; }
145 set { unique = value; }
149 /// Gets or sets the formula used to calculate this property
151 /// <value>The formula.</value>
152 public String Formula
154 get { return formula; }
155 set { formula = value; }
159 /// Gets or sets the type of the column.
161 /// <value>The type of the column.</value>
162 public String ColumnType
165 set { type = value; }
169 /// From NHibernate documentation:
170 /// A unique-key attribute can be used to group columns
171 /// in a single unit key constraint.
173 /// <value>unique key name</value>
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.
180 public string UniqueKey
182 get { return uniqueKey; }
183 set { uniqueKey = value; }
187 /// From NHibernate documentation:
188 /// specifies the name of a (multi-column) index
190 /// <value>index name</value>
193 get { return index; }
194 set { index = value; }
198 /// From NHibernate documentation:
199 /// overrides the default column type
201 /// <value>column_type</value>
202 public string SqlType
204 get { return sqlType; }
205 set { sqlType = value; }
209 /// From NHibernate documentation:
210 /// create an SQL check constraint on either column or table
212 /// <value>Sql Expression</value>
215 get { return check; }
216 set { check = value; }
220 /// Set to <c>true</c> if this property overrides a property in a base class
222 public bool IsOverride
224 get { return isOverride; }
225 set { isOverride = value; }