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
.Tests
.Model
17 using System
.Collections
;
18 using Iesi
.Collections
;
20 [ActiveRecord("Product")]
21 public class Product
: ActiveRecordBase
24 private string product_name
;
26 private string serial_number
;
29 [PrimaryKey(PrimaryKeyType
.Native
, "ProductID")]
32 get { return this.id; }
33 set { this.id = value; }
39 get { return this.product_name; }
40 set { this.product_name = value; }
44 public string SerialNumber
46 get { return this.serial_number; }
47 set { this.serial_number = value; }
53 get { return this.price; }
54 set { this.price = value; }
57 [HasAndBelongsToMany(typeof (Order
), RelationType
.Set
,
59 ColumnRef
="order_id", ColumnKey
="product_id", Inverse
=true)]
62 get { return _orders; }
63 set { _orders = value; }
66 public static Product
Find(int id
)
68 return ((Product
) (ActiveRecordBase
.FindByPrimaryKey(typeof (Product
), id
)));
71 public static void DeleteAll()
73 ActiveRecordBase
.DeleteAll(typeof (Product
));
77 [ActiveRecord("Product")]
78 public class ProductWithIDBag
: ActiveRecordBase
81 private string product_name
;
83 private string serial_number
;
84 private IList _orders
;
86 [PrimaryKey(PrimaryKeyType
.Native
, "ProductID")]
89 get { return this.id; }
90 set { this.id = value; }
96 get { return this.product_name; }
97 set { this.product_name = value; }
101 public string SerialNumber
103 get { return this.serial_number; }
104 set { this.serial_number = value; }
110 get { return this.price; }
111 set { this.price = value; }
114 [HasAndBelongsToMany(typeof (OrderWithIDBag
), RelationType
.IdBag
,
115 Table
="line_item_non_ident",
116 ColumnRef
="order_id", ColumnKey
="product_id"),
117 CollectionID(CollectionIDType
.HiLo
, "line_number", "Int32"),
118 Hilo(Table
="testing_hilo", Column
="sequence", MaxLo
=150)]
121 get { return _orders; }
122 set { _orders = value; }
125 public static ProductWithIDBag
Find(int id
)
127 return ((ProductWithIDBag
) (ActiveRecordBase
.FindByPrimaryKey(typeof (ProductWithIDBag
), id
)));
130 public static void DeleteAll()
132 ActiveRecordBase
.DeleteAll(typeof (ProductWithIDBag
));