Applied patch from Jan Limpens 'ReflectionBasedDictionaryAdapter needs to check if...
[castle.git] / ActiveRecord / Castle.ActiveRecord.Tests / Model / GenericModel / Blog.cs
blob9464cee240f14a2c55de1a05b773a5d822956df9
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.ActiveRecord.Tests.Model.GenericModel
17 using System;
18 using System.Collections;
19 using System.Collections.Generic;
21 using NHibernate;
23 using Castle.ActiveRecord;
24 using Castle.ActiveRecord.Framework;
27 [ActiveRecord("BlogTable")]
28 public class Blog : ActiveRecordBase<Blog>
30 private int _id;
31 private String _name;
32 private String _author;
33 private IList<Post> _posts = new List<Post>();
34 private IList _publishedposts;
35 private IList _unpublishedposts;
36 private IList _recentposts;
38 [PrimaryKey]
39 public int Id
41 get { return _id; }
42 set { _id = value; }
45 [Property]
46 public String Name
48 get { return _name; }
49 set { _name = value; }
52 [Property]
53 public String Author
55 get { return _author; }
56 set { _author = value; }
59 [HasMany(Table="Posts", ColumnKey="blogid")]
60 public IList<Post> Posts
62 get { return _posts; }
63 set { _posts = value; }
66 [HasMany(typeof (Post), Table="Posts", ColumnKey="blogid", Where="published = 1")]
67 public IList PublishedPosts
69 get { return _publishedposts; }
70 set { _publishedposts = value; }
73 [HasMany(typeof (Post), Table="Posts", ColumnKey="blogid", Where="published = 0")]
74 public IList UnPublishedPosts
76 get { return _unpublishedposts; }
77 set { _unpublishedposts = value; }
80 [HasMany(typeof (Post), Table="Posts", ColumnKey="blogid", OrderBy="created desc")]
81 public IList RecentPosts
83 get { return _recentposts; }
84 set { _recentposts = value; }
87 public void CustomAction()
89 ActiveRecordMediator<Blog>.Execute(new NHibernateDelegate(MyCustomMethod), this);
92 private object MyCustomMethod(ISession session, object blogInstance)
94 session.Delete(blogInstance);
95 session.Flush();
97 return null;
100 internal static ISessionFactoryHolder Holder
102 get { return ActiveRecordMediator<Blog>.GetSessionFactoryHolder(); }