NHibernate: Is it possible to leave (var tx = session.BeginTransaction ()) {} without Commit () while reading?

Quick question .. In a function that checks if a specific terminal identifier is available, is it suitable for me for this, as shown below?

using (var tx = session.BeginTransaction())
{
    return ((new TerminalDAO(sm.Session)).Get(tid) == null) ? true : false;
}

Or is it advisable to do this using the Commit () function?

Terminal terminal = null;
using (var tx = session.BeginTransaction())
{
    terminal = (new TerminalDAO(session)).Get(tid);
    tx.Commit();
}
return (terminal == null) ? true : false;
+4
source share
1 answer

For operations with readonly - I would first of all evaluate you that you included the transaction even for working with readonly, and also suggest using rollback and actually explicit rollback .

Please check the following:

Rollback():

  • ? , READ, WRITE .
  • ? , , . - . (, )
+5

All Articles