示例#1
0
        public AppSessionFactory(DatabaseOptions options)
        {
            var mapper = new ModelMapper();

            mapper.AddZooMappings();
            var domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            var configuration = new Configuration();

            configuration.SessionFactoryName(options.InstanceName);
            configuration.DataBaseIntegration(db =>
            {
                db.ConnectionString = options.ConnectionString;
                db.Dialect <MsSql2012Dialect>();
                db.Driver <SqlClientDriver>();
                db.LogFormattedSql = true;
                db.LogSqlInConsole = true;
                db.AutoCommentSql  = true;
            })
            .AddMapping(domainMapping);
            configuration.SessionFactory().GenerateStatistics();
            _sessionFactory = configuration.BuildSessionFactory();

            new SchemaUpdate(configuration).Execute(false, true);
        }