I will session.Saveorupdate(Entity).
example:
Code:
[Test]
[ExpectedException(typeof(ServiceExceptionUserAlreadyExisted))]
public void AddUserWithAnExistedLoginInfo()
{
IDAL dal = new DALImpl();
Person perEntity = new Person();
perEntity.Name = "TestPerson";
LoginInfo logifo = new LoginInfo();
//loginname Field is unique="true" in the database
logifo.LoginName = "admin";
logifo.Password = "123";
//one- to -one
perEntity.TheLoginInfo = logifo;
logifo.ThePerson = perEntity;
dal.SaveEntity(perEntity);
}
because "admin" is exist in the Database. so session.transaction.commit is throw exception:
Code:
InnerException = {"Violation of UNIQUE KEY constraint 'UQ__TLoginInfo__38E54BF0'. Cannot insert duplicate key in object 'TLoginInfo'.\r\nThe statement has been terminated."}
And session.transaction.rollback(), but rollback shall again throw exception:
Code:
{"Object reference not set to an instance of an object."}
Why???