Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / Facilities / ActiveRecordIntegration / Castle.Facilities.ActiveRecordIntegration.Tests / Model / Post.cs
bloba0b2c470ce8f2163bc537fa8e906c5ded3ecfed1
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 Castle.Facilities.ActiveRecordIntegration.Tests
17 using System;
18 using System.Collections;
20 using Castle.ActiveRecord;
22 [ActiveRecord("Posts")]
23 public class Post : ActiveRecordBase
25 private int _id;
26 private String _title;
27 private String _contents;
28 private String _category;
29 private DateTime _created;
30 private bool _published;
31 private Blog _blog;
33 public Post()
37 public Post(Blog blog, String title, String contents, String category)
39 _blog = blog;
40 _title = title;
41 _contents = contents;
42 _category = category;
45 [PrimaryKey(PrimaryKeyType.Native)]
46 public int Id
48 get { return _id; }
49 set { _id = value; }
52 [Property]
53 public String Title
55 get { return _title; }
56 set { _title = value; }
59 [Property(ColumnType="StringClob")]
60 public String Contents
62 get { return _contents; }
63 set { _contents = value; }
66 [Property]
67 public String Category
69 get { return _category; }
70 set { _category = value; }
73 [BelongsTo("blogid")]
74 public Blog Blog
76 get { return _blog; }
77 set { _blog = value; }
80 [Property("created")]
81 public DateTime Created
83 get { return _created; }
84 set { _created = value; }
87 [Property("published")]
88 public bool Published
90 get { return _published; }
91 set { _published = value; }
94 protected override bool BeforeSave(IDictionary state)
96 state["Created"] = DateTime.Now;
97 return true;
100 public static void DeleteAll()
102 ActiveRecordBase.DeleteAll( typeof(Post) );
105 public static Post[] FindAll()
107 return (Post[]) ActiveRecordBase.FindAll( typeof(Post) );