I am writing an integration test where I am checking to put several objects into a database and then to make sure Will my method get those items?
My connection to the database is through NHibernate ... and my usual method of making such a test will be:
NHibernateSession.BeginTransaction () ; // Use nhibernate to insert objects through your system / Recover / verify real objects by means of my method, they are similar to the NHibernateSession.RollbackTransaction () inserted;
However, I have recently figured out which purpose can be used for this purpose ...
Some are as follows:
Staff (Department Department) with Public Static In Department {int res = 0; Department adapter department adapter = new department adapter (); Employee adapter empAdapter = new employee adapter (); (Use the transaction scope txScope = new transaction scope ()) {res + = deptAdapter.Insert (dept.DepartmentName); After identifying the department, custom method "Identification columns" section to return the department ID / ID Department id = deputy adapter. Getinist return value (); Foreign currency (employee employee in the department) {emp.EmployeeDeptID = dept.DepartmentID; Res + = empAdapter.Insert (emp.EmployeeName, emp.EmployeeDeptID); } TxScope.Complete (); } Return Ridge; }
I believe if the line txScope.Complete ()
is not included then the data will be returned. But unfortunately I do not understand how this is possible ... txscope
object keeps track of how the deptAdapter
and empAdapter
and Their transaction on databases
I think I have not got any information here ... am I really able to change my BeginTransaction ()
and RollbackTransaction (
) By using TransactionScope
calls my code around?
If not, then how does transaction scope
work to roll back the transaction?
Essentially TransactionScope does not track your adapter, it does what it does to track this database connection When you open a DB connection, connections will occur if there is an ambient transaction (transfer area) and if so, register with it. Caution If a connection is more than the same SQL Server, then it will increase a distributed transaction.
What happens when you are using the block you are using, so that you are making sure that an exception occurs. So if the settlement is called before TCS -SCOP. TransactionScope will tell the full () return to your transaction (or DTC) connection.
Comments
Post a Comment