Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Samples / Castle / PetStore.Model / Category.cs
blob16e8c6f66c0013405549fe077f8732d2f13ac2fe
1 // Copyright 2004-2008 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 PetStore.Model
17 using System;
19 using Castle.ActiveRecord;
21 using Iesi.Collections;
23 using NHibernate.Expression;
26 [ActiveRecord]
27 public class Category : ActiveRecordBase
29 private int id;
30 private String name;
31 private Category parent;
32 private ISet subcategories = new HashedSet();
33 private ISet products = new HashedSet();
35 [PrimaryKey]
36 public int Id
38 get { return id; }
39 set { id = value; }
42 [Property]
43 public string Name
45 get { return name; }
46 set { name = value; }
49 [BelongsTo("parent_category_id")]
50 public Category Parent
52 get { return parent; }
53 set { parent = value; }
56 public bool IsRoot
58 get { return Parent == null; }
61 /// <summary>
62 /// Lazy means: load the collections content only when used.
63 /// and inverse means that the other end controls
64 /// the relation
65 /// </summary>
66 [HasMany( typeof(Category), Inverse=true, Lazy=true, OrderBy="Name ASC" )]
67 public ISet SubCategories
69 get { return subcategories; }
70 set { subcategories = value; }
73 /// <summary>
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
77 /// the relation.
78 /// </summary>
79 [HasMany( typeof(Product), Inverse=true, Lazy=true )]
80 public ISet Products
82 get { return products; }
83 set { products = value; }
86 /// <summary>
87 /// We have overrided the implementation of
88 /// ToString only because this class in being
89 /// used on the ActiveRecord Scaffolding
90 /// </summary>
91 /// <returns></returns>
92 public override string ToString()
94 return "" + name;
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);