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
18 using System
.Collections
;
22 using Castle
.ActiveRecord
.Framework
;
25 [ActiveRecord("BlogTable")]
26 public class BlogLazy
: ActiveRecordBase
30 private String _author
;
32 private IList _publishedposts
;
34 [PrimaryKey(PrimaryKeyType
.Native
)]
45 set { _name = value; }
51 get { return _author; }
52 set { _author = value; }
55 [HasMany(typeof(PostLazy
), Table
="Posts", ColumnKey
="blogid", Lazy
=true)]
58 get { return _posts; }
59 set { _posts = value; }
62 [HasMany(typeof(PostLazy
), Table
="Posts", ColumnKey
="blogid", Where
="published = 1", Lazy
=true)]
63 public IList PublishedPosts
65 get { return _publishedposts; }
66 set { _publishedposts = value; }
69 public static void DeleteAll()
71 ActiveRecordBase
.DeleteAll( typeof(BlogLazy
) );
74 public static BlogLazy
[] FindAll()
76 return (BlogLazy
[]) ActiveRecordBase
.FindAll( typeof(BlogLazy
) );
79 public static BlogLazy
Find(int id
)
81 return (BlogLazy
) ActiveRecordBase
.FindByPrimaryKey( typeof(BlogLazy
), id
);
85 /// We make it visible only to for test cases' assertions
87 public static ISessionFactoryHolder Holder
89 get { return ActiveRecordMediator.GetSessionFactoryHolder(); }
92 public void CustomAction()
94 Execute(new NHibernateDelegate(MyCustomMethod
));
97 private object MyCustomMethod(ISession session
, object blogInstance
)
99 session
.Delete(blogInstance
);