Castle.Facilities.AutoTx problem

5 views
Skip to first unread message

languanghao

unread,
Jan 11, 2011, 8:35:33 PM1/11/11
to Castle Project Development List
Hi,

I used Castle.Facilities.AutoTx in my program, but it didn't work.

Code:
namespace BLL.IMPL.User
{
[Transactional]
public class UserInfoManagerIMPL : InitializingCastle,
IUserInfoManager
{

[Transaction(Castle.Services.Transaction.TransactionMode.Requires)]
public virtual bool AddUserInfo(UserInfo user)
{
ActiveRecordMediator<UserInfo>.Create(user);
throw new Exception("test");
}


This method throw an Exception,but the userinfo has commit.

Krzysztof Koźmic

unread,
Jan 11, 2011, 8:37:43 PM1/11/11
to castle-pro...@googlegroups.com
How did you create this object?

languanghao

unread,
Jan 11, 2011, 8:50:20 PM1/11/11
to Castle Project Development List
The unit test code:
public class TestUserInfo
{
[Test]
public void TestInsert()
{
IUserInfoManager uimanager =
ObjectFactory.Container.UserInfoManager;
UserInfo ui = new UserInfo();
ui.LoginName = "test9";
ui.LoginPassWord = "123@abc";
ui.LastEditPassWordDate = DateTime.Now;
ui.BaseInfo = new UserBaseInfo { Gender = GenderEnum.Male,
UserName = "test1", User = ui };
uimanager.AddUserInfo(ui);
}
}

The UserInfo model:
namespace DAL.Model.User
{
[ActiveRecord(Lazy=true)]
public class UserInfo
{
public UserInfo()
{
IsEnabled = true;
IsLocked = false;
}

[PrimaryKey(PrimaryKeyType.Guid)]
public virtual Guid SID { get; set; }

[Property]
public virtual string LoginName { get; set; }

[Property]
public virtual string LoginPassWord { get; set; }


[Property]
public virtual DateTime LastEditPassWordDate { get; set; }


[Property]
public virtual bool IsLocked { get; set; }


[Property]
public virtual bool IsEnabled { get; set; }


[OneToOne(Cascade = CascadeEnum.All)]
public virtual UserBaseInfo BaseInfo { get; set; }
}
}

On 1月12日, 上午9时37分, Krzysztof Koźmic <krzysztof.koz...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages