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
.GenericModel
18 using System
.Collections
;
19 using System
.Collections
.Generic
;
23 using Castle
.ActiveRecord
;
24 using Castle
.ActiveRecord
.Framework
;
27 [ActiveRecord("BlogTable")]
28 public class Blog
: ActiveRecordBase
<Blog
>
32 private String _author
;
33 private IList
<Post
> _posts
= new List
<Post
>();
34 private IList _publishedposts
;
35 private IList _unpublishedposts
;
36 private IList _recentposts
;
49 set { _name = value; }
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
);
100 internal static ISessionFactoryHolder Holder
102 get { return ActiveRecordMediator<Blog>.GetSessionFactoryHolder(); }