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
18 using System
.Collections
;
20 [ActiveRecord("PostTable")]
21 public class Post
: ActiveRecordBase
24 private String _title
;
25 private String _contents
;
26 private String _category
;
27 private DateTime _created
;
28 private bool _published
;
35 public Post(Blog blog
, String title
, String contents
, String category
)
43 [PrimaryKey(PrimaryKeyType
.Native
)]
53 get { return _title; }
54 set { _title = value; }
57 [Property(ColumnType
="StringClob")]
58 public String Contents
60 get { return _contents; }
61 set { _contents = value; }
65 public String Category
67 get { return _category; }
68 set { _category = value; }
75 set { _blog = value; }
79 public DateTime Created
81 get { return _created; }
82 set { _created = value; }
85 [Property("published")]
88 get { return _published; }
89 set { _published = value; }
92 protected override bool BeforeSave(IDictionary state
)
94 state
["Created"] = DateTime
.Now
;
98 public static void DeleteAll()
100 DeleteAll(typeof(Post
));
103 public static Post
[] FindAll()
105 return (Post
[]) FindAll(typeof(Post
));
108 public static Post
Find(int id
)
110 return (Post
) FindByPrimaryKey(typeof(Post
), id
);
113 public static int FetchCount()
115 return Count(typeof(Post
));
118 public static int FetchCount(string filter
, params object[] args
)
120 return Count(typeof(Post
), filter
, args
);
123 public void SaveWithException()
127 throw new ApplicationException("Fake Exception");