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
.CompositeModel
18 using System
.Collections
;
22 using Castle
.ActiveRecord
.Framework
;
25 [ActiveRecord("Agents")]
26 public class Agent
: ActiveRecordBase
28 private AgentKey _userKey
;
30 private IList _groups
;
35 _groups
= new ArrayList();
39 public Agent(AgentKey key
) : this()
47 get { return _userKey; }
48 set { _userKey = value; }
53 get { return _userKey.OrgId; }
58 get { return _userKey.Name; }
61 [Version(UnsavedValue
="negative")]
64 get{ return _version; }
65 set{ _version = value; }
68 [BelongsTo("OrgId", Insert
=false, Update
=false)]
75 [HasAndBelongsToMany(typeof (Group
),
76 Table
= "GroupAgents",
77 ColumnRef
= "GroupId",
78 CompositeKeyColumnKeys
= new String
[]{"OrgId","Name"}
,
80 Cascade
= ManyRelationCascadeEnum
.SaveUpdate
)]
83 get { return _groups; }
84 set { _groups = value; }
87 public static void DeleteAll()
89 ActiveRecordBase
.DeleteAll( typeof(Agent
) );
92 public static Agent
[] FindAll()
94 return (Agent
[]) ActiveRecordBase
.FindAll( typeof(Agent
) );
97 public static Agent
Find(object key
)
99 return (Agent
) ActiveRecordBase
.FindByPrimaryKey( typeof(Agent
), key
);
103 /// We make it visible only to for test cases' assertions
105 public static ISessionFactoryHolder Holder
107 get { return ActiveRecordMediator.GetSessionFactoryHolder(); }
110 public void CustomAction()
112 Execute(new NHibernateDelegate(MyCustomMethod
));
115 private object MyCustomMethod(ISession session
, object userInstance
)
117 session
.Delete(userInstance
);