Ejemplo n.º 1
0
        static void CreateDatabase()
        {
            var configuration = new NHibernate.Cfg.Configuration();
            var _mapper       = new CustomModelMapper();

            configuration.DataBaseIntegration((x) =>
            {
                x.ConnectionString = @"Data Source=localhost;Initial Catalog=EnversBug;Persist Security Info=True;User ID=sa;Password=sa2008~";
                x.Dialect <MsSql2012Dialect>();
            });

            var types = typeof(Entity <>)
                        .Assembly
                        .GetTypes()
                        .Where(t => !t.IsInterface && !t.IsGenericType)
            ;

            _mapper.AddMappings(types);

            configuration.AddMapping(_mapper.CompileMappingFor(types));

            configuration.SetEnversProperty(ConfigurationKey.AuditTableSuffix, "_A");
            configuration.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true);
            configuration.SetEnversProperty(ConfigurationKey.RevisionOnCollectionChange, false);

            var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();

            enversConf.Audit(types);

            configuration.IntegrateWithEnvers(enversConf);


            var exporter = new SchemaExport(configuration);

            exporter.Execute(true, true, false);

            _sessionFactory = configuration.BuildSessionFactory();
        }