コード例 #1
0
ファイル: OrmConfig.cs プロジェクト: Enzogord/QSProjects
        /// <summary>
        /// Настройка Nhibernate только с Fluent конфигураций.
        /// </summary>
        /// <param name="assemblies">Assemblies.</param>
        public static void ConfigureOrm(FluentNHibernate.Cfg.Db.IPersistenceConfigurer database, System.Reflection.Assembly[] assemblies, Action <Configuration> exposeConfiguration = null)
        {
            fluenConfig = Fluently.Configure().Database(database);

            fluenConfig.Mappings(m => {
                foreach (var ass in assemblies)
                {
                    m.FluentMappings.AddFromAssembly(ass);
                }
            });

            var trackerListener = new NhEventListener();

            fluenConfig.ExposeConfiguration(cfg => {
                cfg.AppendListeners(NHibernate.Event.ListenerType.PostLoad, new[] { trackerListener });
                cfg.AppendListeners(NHibernate.Event.ListenerType.PreLoad, new[] { trackerListener });
                cfg.AppendListeners(NHibernate.Event.ListenerType.PostDelete, new[] { trackerListener });
                cfg.AppendListeners(NHibernate.Event.ListenerType.PostUpdate, new[] { trackerListener });
                cfg.AppendListeners(NHibernate.Event.ListenerType.PostInsert, new[] { trackerListener });
            });

            if (exposeConfiguration != null)
            {
                fluenConfig.ExposeConfiguration(exposeConfiguration);
            }

            Sessions = fluenConfig.BuildSessionFactory();
        }
コード例 #2
0
ファイル: UnitOfWorkBase.cs プロジェクト: Enzogord/QSProjects
 public void Dispose()
 {
     if (transaction != null)
     {
         if (!transaction.WasCommitted && !transaction.WasRolledBack)
         {
             transaction.Rollback();
         }
         transaction.Dispose();
         transaction = null;
     }
     Session.Dispose();
     NhEventListener.UnregisterUow(this);
 }