Ejemplo n.º 1
0
 /// <summary>
 /// Call <see cref="NHibernateSessionExtensions.TransactionalFlush"/> on the session returned by
 /// <see cref="ISessionFactory.GetCurrentSession"/>
 /// </summary>
 /// <param name="sessionFactory">The session factory that will return the current session</param>
 /// <param name="openNewSessionOnFailure">
 /// When true, <see cref="StartCurrentSession"/> will be called to create a new session when an exception is thrown
 /// </param>
 /// <remarks>
 /// <para>
 /// After a successfull flush, if it is detected that the main executable program is running within the ASP.Net host,
 /// a new <see cref="ITransaction"/> will be started.  This is to ensure that by any subsequent communication within
 /// the database is performed within a transaction - an important NHibernate best practice.
 /// </para>
 /// <para>
 /// However, a new transaction will not be opened if a an exception is thrown and <paramref name="openNewSessionOnFailure"/>
 /// was set to false.
 /// </para>
 /// </remarks>
 public static void TransactionalFlushCurrentSession(this ISessionFactory sessionFactory,
                                                     bool openNewSessionOnFailure)
 {
     try
     {
         sessionFactory.GetCurrentSession().TransactionalFlush();
     }
     catch (Exception)
     {
         sessionFactory.DisposeCurrentSession();
         if (openNewSessionOnFailure)
         {
             sessionFactory.StartCurrentSession();
         }
         throw;
     }
     if (IsAspNetProcess)
     {
         sessionFactory.GetCurrentSession().BeginTransaction();
     }
 }