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 Castle
.ActiveRecord
.Tests
.Model
.CompositeModel
18 using System
.Collections
;
20 [ActiveRecord("Orgs")]
21 public class Org
: ActiveRecordBase
24 private String _description
;
25 private DateTime _created
;
26 private IList _agents
;
31 _agents
= new ArrayList();
32 _created
= DateTime
.Now
;
36 public Org(string id
, String description
) : this()
39 _description
= description
;
42 [PrimaryKey(PrimaryKeyType
.Assigned
)]
49 [Version(UnsavedValue
="negative")]
52 get { return _version; }
53 set { _version = value; }
56 [Property(ColumnType
="StringClob")]
57 public String Contents
59 get { return _description; }
60 set { _description = value; }
63 [HasMany(typeof(Agent
),
68 get { return _agents; }
69 set { _agents = value; }
73 public DateTime Created
75 get { return _created; }
76 set { _created = value; }
79 protected override bool BeforeSave(IDictionary state
)
81 state
["Created"] = DateTime
.Now
;
85 public static void DeleteAll()
87 DeleteAll(typeof(Org
));
90 public static Org
[] FindAll()
92 return (Org
[]) FindAll(typeof(Org
));
95 public static Org
Find(string id
)
97 return (Org
) FindByPrimaryKey(typeof(Org
), id
);
100 public static int FetchCount()
102 return Count(typeof(Org
));
105 public static int FetchCount(string filter
, params object[] args
)
107 return Count(typeof(Org
), filter
, args
);
110 public void SaveWithException()
114 throw new ApplicationException("Fake Exception");