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 /// Defines the values for the generator for the Collection Id values.w
23 public enum CollectionIDType
26 /// Use Identity column (auto number)
34 /// Use the HiLo algorithm to get the next value
38 /// Use a sequence and a HiLo algorithm - better performance on Oracle
42 /// Use the hex representation of a unique identifier
46 /// Use the string representation of a unique identifier
50 /// Generate a Guid for the primary key
51 /// Note: You should prefer using GuidComb over this value.
55 /// Generate a Guid in sequence, so it will have better insert performance in the DB.
59 /// The key value is always assigned.
63 /// This is a foreign key to another table
69 /// Used for a collection that requires a collection id.
72 /// public class Blog : ActiveRecordBase
76 /// [HasManyAndBelongs/HasMany]
77 /// [CollectionIDAttribute(CollectionIDAttribute.Native)]
80 /// get { return _id; }
81 /// set { _id = value; }
84 [AttributeUsage(AttributeTargets
.Property
, AllowMultiple
=false), Serializable
]
85 public class CollectionIDAttribute
: Attribute
87 private CollectionIDType generator
= CollectionIDType
.Assigned
;
88 private String column
;
92 /// Initializes a new instance of the <see cref="CollectionIDAttribute"/> class.
94 /// <param name="generator">The generator.</param>
95 /// <param name="column">The column.</param>
96 /// <param name="ColumnType">Type of the column.</param>
97 public CollectionIDAttribute(CollectionIDType generator
, String column
, String ColumnType
)
99 this.generator
= generator
;
100 this.column
= column
;
101 this.type
= ColumnType
;
105 /// Gets or sets the generator.
107 /// <value>The generator.</value>
108 public CollectionIDType Generator
110 get { return generator; }
111 set { generator = value; }
115 /// Gets or sets the column name
117 /// <value>The column.</value>
120 get { return column; }
121 set { column = value; }
125 /// Gets or sets the type of the column.
127 /// <value>The type of the column.</value>
128 public String ColumnType
131 set { type = value; }