Fixing IOC-63
[castle.git] / Samples / ActiveRecord / TableHierarchySample / Company.cs
blob5adacf42f3076cc0939df4b540140befdd90c9d0
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 TableHierarchySample
17 using System;
18 using System.Collections;
20 using Castle.ActiveRecord;
23 [ActiveRecord("Companies", DiscriminatorColumn="type", DiscriminatorType="String", DiscriminatorValue="company")]
24 public class Company : ActiveRecordBase
26 private int id;
27 private String name;
28 private IList _people;
30 public Company()
34 public Company(string name)
36 this.name = name;
39 [PrimaryKey]
40 public int Id
42 get { return id; }
43 set { id = value; }
46 [Property]
47 public String Name
49 get { return name; }
50 set { name = value; }
53 [HasAndBelongsToMany( typeof(Person), Table="PeopleCompanies", ColumnRef="person_id", ColumnKey="company_id" )]
54 public IList People
56 get { return _people; }
57 set { _people = value; }
60 public static void DeleteAll()
62 ActiveRecordBase.DeleteAll( typeof(Company) );
65 public static Company[] FindAll()
67 return (Company[]) ActiveRecordBase.FindAll( typeof(Company) );
70 public static Company Find(int id)
72 return (Company) ActiveRecordBase.FindByPrimaryKey( typeof(Company), id );