Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / ActiveRecord / Castle.ActiveRecord.Framework.Internal.Tests / Model / CompositeKeyModels.cs
blob859c0e32f2321d37a6569d8ac52dcac948637f52
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
19 #region CompositeKey2
21 [Serializable]
22 public class CompositeKey2
24 private int key1;
25 private String key2;
27 [KeyProperty]
28 public int Key1
30 get { return key1; }
31 set { key1 = value; }
34 [KeyProperty]
35 public string Key2
37 get { return key2; }
38 set { key2 = value; }
41 public override int GetHashCode()
43 return key1 + 29*(key2 != null ? key2.GetHashCode() : 0);
46 public override bool Equals(object obj)
48 if (this == obj)
50 return true;
52 CompositeKey2 compositeKey2 = obj as CompositeKey2;
53 if (compositeKey2 == null)
55 return false;
57 if (key1 != compositeKey2.key1)
59 return false;
61 if (!Equals(key2, compositeKey2.key2))
63 return false;
65 return true;
69 #endregion
71 /// <summary>
72 /// Simplest case for CompositeKey support on AR
73 /// </summary>
74 [ActiveRecord(Lazy = false)]
75 public class ClassWithCompositeKey2 : ActiveRecordBase
77 private CompositeKey2 key;
79 [CompositeKey]
80 public CompositeKey2 Key
82 get { return this.key; }
83 set { this.key = value; }
87 #region CompositeKey3
89 [Serializable]
90 public class CompositeKey3
92 private Product product;
93 private int someOtherKey;
95 [BelongsTo]
96 public Product Product
98 get { return this.product; }
99 set { this.product = value; }
102 [KeyProperty]
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)
116 if (this == obj)
118 return true;
120 CompositeKey3 compositeKey3 = obj as CompositeKey3;
121 if (compositeKey3 == null)
123 return false;
125 if (!Equals(product, compositeKey3.product))
127 return false;
129 if (someOtherKey != compositeKey3.someOtherKey)
131 return false;
133 return true;
137 #endregion
139 /// <summary>
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)
142 /// </summary>
143 [ActiveRecord(Lazy = false)]
144 public class ClassWithCompositeKey3 : ActiveRecordBase
146 private CompositeKey3 key;
148 [CompositeKey]
149 public CompositeKey3 Key
151 get { return this.key; }
152 set { this.key = value; }
156 [ActiveRecord("Product", Lazy = false)]
157 public class Product : ActiveRecordBase
159 private int id;
160 private string product_name;
161 private float price;
162 private string serial_number;
164 [PrimaryKey(PrimaryKeyType.Native, "ProductID")]
165 public int ID
167 get { return this.id; }
168 set { this.id = value; }
171 [Property]
172 public string Name
174 get { return this.product_name; }
175 set { this.product_name = value; }
178 [Property]
179 public string SerialNumber
181 get { return this.serial_number; }
182 set { this.serial_number = value; }
185 [Property]
186 public float Price
188 get { return this.price; }
189 set { this.price = value; }