Can you use a using-statement with sessions and transactions that will close the session and roll back the transaction if exception is thrown?
Also, isn't this a better way of writing the code?
Like so:
Code:
using (ISession session= _SessionFactory.OpenSession())
{
//here are some checks, some other code and some stuff as well...
//loading persistent classes
using (ITransaction transaction = session.BeginTransaction())
{
try
{
//Create some new objects/change properties of the objects
session.Update(myobject);
transaction.Commit();
}
catch
{
transaction.Rollback();
}
}
}