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
;
20 [ActiveRecord("PostTable", Lazy
=true)]
21 public class PostLazy
: ActiveRecordBase
24 private String _title
;
25 private String _contents
;
26 private String _category
;
27 private DateTime _created
;
28 private bool _published
;
29 private BlogLazy _blog
;
35 public PostLazy(BlogLazy blog
, String title
, String contents
, String category
)
43 [PrimaryKey(PrimaryKeyType
.Native
)]
51 public virtual String Title
53 get { return _title; }
54 set { _title = value; }
57 [Property(ColumnType
="StringClob")]
58 public virtual String Contents
60 get { return _contents; }
61 set { _contents = value; }
65 public virtual String Category
67 get { return _category; }
68 set { _category = value; }
72 public virtual BlogLazy Blog
75 set { _blog = value; }
79 public virtual DateTime Created
81 get { return _created; }
82 set { _created = value; }
85 [Property("published")]
86 public virtual bool 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 ActiveRecordBase
.DeleteAll( typeof(PostLazy
) );
103 public static PostLazy
[] FindAll()
105 return (PostLazy
[]) ActiveRecordBase
.FindAll( typeof(PostLazy
) );
108 public static PostLazy
Find(int id
)
110 return (PostLazy
) FindByPrimaryKey(typeof (PostLazy
), id
);
113 public virtual void SaveWithException()
117 throw new ApplicationException("Fake Exception");