我有一個BO(國家)與一個孩子BO(州),其中也有一個孩子BO(市)。當我更新父BO(國家)時,添加一個子狀態並運行保存,當發生DAL異常(故意)時,事務不會回滾。我正在使用SqlCE。我附上一個示範項目來證明這個問題。我究竟做錯了什麼?TransactionScope不會回滾異常CSLA 4.3
測試代碼:
Country originalCountry = null;
try
{
originalCountry = Country.GetCountry(1);
var country = Country.GetCountry(1);
country.CountryName = "My new name";
var state = country.States.AddNew();
state.StateName = "Dummy state";
country.States.EndNew(country.States.IndexOf(state));
country.Save();
}
catch (Exception exception)
{
var country = Country.GetCountry(1);
if (originalCountry.CountryName != country.CountryName)
{
System.Console.WriteLine("Values ARE NOT the same: " + originalCountry.CountryName + " vs. " + country.CountryName);
}
else
{
System.Console.WriteLine("Values are the same: " + originalCountry.CountryName + " vs. " + country.CountryName);
}
}
Country.cs
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
Update();
}
private void Update()
{
using (var ctx = DalFactory.GetManager())
{
var dal = ctx.GetProvider<ICountryDal>();
using (BypassPropertyChecks)
{
var dto = new CountryDto();
TransferToDto(dto);
dal.Update(dto);
}
FieldManager.UpdateChildren(this);
throw new Exception("Rollback should occur.");
}
}
我在里昂證券論壇的答案,你是在正確的軌道上。在我的商業規則中,我沒有正確處理DalManager導致問題。 – Mensur 2013-02-13 13:55:32