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
;
20 using NHibernate
.Expression
;
23 public class Product
: ActiveRecordBase
27 private String description
;
28 private String pictureFile
;
29 private decimal price
;
30 private Category category
;
47 public string Description
49 get { return description; }
50 set { description = value; }
54 public string PictureFile
56 get { return pictureFile; }
57 set { pictureFile = value; }
64 set { price = value; }
67 [BelongsTo("category_id")]
68 public Category Category
70 get { return category; }
71 set { category = value; }
74 public static Product
Find(int id
)
76 return (Product
) FindByPrimaryKey( typeof(Product
), id
);
79 public static Product
[] FindAll()
81 return (Product
[]) FindAll(
82 typeof(Product
), new Order
[] { Order.Asc("Name") }
);
85 public static Product
[] FindByCategory(int category
)
87 return (Product
[]) FindAll(
88 typeof(Product
), new Order
[] { Order.Asc("Name") }
, Expression
.Eq("Category.Id", category
) );