1 // Copyright 2004-2007 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
.Framework
.Internal
.Tests
.Model
22 public class CompositeKey2
41 public override int GetHashCode()
43 return key1
+ 29*(key2
!= null ? key2
.GetHashCode() : 0);
46 public override bool Equals(object obj
)
52 CompositeKey2 compositeKey2
= obj
as CompositeKey2
;
53 if (compositeKey2
== null)
57 if (key1
!= compositeKey2
.key1
)
61 if (!Equals(key2
, compositeKey2
.key2
))
72 /// Simplest case for CompositeKey support on AR
74 [ActiveRecord(Lazy
= false)]
75 public class ClassWithCompositeKey2
: ActiveRecordBase
77 private CompositeKey2 key
;
80 public CompositeKey2 Key
82 get { return this.key; }
83 set { this.key = value; }
90 public class CompositeKey3
92 private Product product
;
93 private int someOtherKey
;
96 public Product Product
98 get { return this.product; }
99 set { this.product = value; }
103 public int SomeOtherKey
105 get { return this.someOtherKey; }
106 set { this.someOtherKey = value; }
109 public override int GetHashCode()
111 return product
.GetHashCode() + 29*someOtherKey
;
114 public override bool Equals(object obj
)
120 CompositeKey3 compositeKey3
= obj
as CompositeKey3
;
121 if (compositeKey3
== null)
125 if (!Equals(product
, compositeKey3
.product
))
129 if (someOtherKey
!= compositeKey3
.someOtherKey
)
140 /// In this case the composite key has a BelongsTo, which should be supported
141 /// as well (must generate key-many-to-one instead of key-property)
143 [ActiveRecord(Lazy
= false)]
144 public class ClassWithCompositeKey3
: ActiveRecordBase
146 private CompositeKey3 key
;
149 public CompositeKey3 Key
151 get { return this.key; }
152 set { this.key = value; }
156 [ActiveRecord("Product", Lazy
= false)]
157 public class Product
: ActiveRecordBase
160 private string product_name
;
162 private string serial_number
;
164 [PrimaryKey(PrimaryKeyType
.Native
, "ProductID")]
167 get { return this.id; }
168 set { this.id = value; }
174 get { return this.product_name; }
175 set { this.product_name = value; }
179 public string SerialNumber
181 get { return this.serial_number; }
182 set { this.serial_number = value; }
188 get { return this.price; }
189 set { this.price = value; }