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 PetStore
.Model
19 using Castle
.ActiveRecord
;
21 using Iesi
.Collections
;
23 using NHibernate
.Expression
;
27 public class Category
: ActiveRecordBase
31 private Category parent
;
32 private ISet subcategories
= new HashedSet();
33 private ISet products
= new HashedSet();
49 [BelongsTo("parent_category_id")]
50 public Category Parent
52 get { return parent; }
53 set { parent = value; }
58 get { return Parent == null; }
62 /// Lazy means: load the collections content only when used.
63 /// and inverse means that the other end controls
66 [HasMany( typeof(Category
), Inverse
=true, Lazy
=true, OrderBy
="Name ASC" )]
67 public ISet SubCategories
69 get { return subcategories; }
70 set { subcategories = value; }
74 /// The Inverse is usually a source of confusion, but it
75 /// more or like make this relation informative, or readonly.
76 /// <see cref="Product"/> is the entity that dictates
79 [HasMany( typeof(Product
), Inverse
=true, Lazy
=true )]
82 get { return products; }
83 set { products = value; }
87 /// We have overrided the implementation of
88 /// ToString only because this class in being
89 /// used on the ActiveRecord Scaffolding
91 /// <returns></returns>
92 public override string ToString()
97 public static Category
[] FindAll()
99 return (Category
[]) FindAll(
100 typeof(Category
), new Order
[] { Order.Asc("Name") }
);
103 public static Category
Find(int id
)
105 return (Category
) FindByPrimaryKey(typeof(Category
), id
);