static ISessionFactory buildSessionFactoryAndExportSchema() { // ReSharper disable once PossibleNullReferenceException // ReSharper disable once AssignNullToNotNullAttribute var sessionFactory = Fluently.Configure(new Configuration()) .Database(SQLiteConfiguration.Standard .InMemory() .Provider <SqliteInMemoryDriverConnectionProvider>() .ShowSql() .FormatSql() .Raw(Environment.GenerateStatistics, "true")) .Mappings(m => m.AutoMappings.Add(AutoMap .Source(Types.FromAssemblies(Assembly.GetExecutingAssembly()) .Where(t => t.Namespace.StartsWith(typeof(NHibernateContext).Namespace) && t.InheritsOrImplements(typeof(IdentityFieldProvider <,>)))) .IgnoreBase(typeof(IdentityFieldProvider <,>)) .Conventions.AddAssembly(typeof(AbbreviationAttribute).Assembly) .UseOverridesFromAssembly(Assembly.GetExecutingAssembly()))) .Diagnostics(x => x.Enable().OutputToConsole()) .ExposeConfiguration(x => { new SqliteRemapper().Remap(x); _configuration = x; }) .BuildSessionFactory(); using (var debug = new DiagnosticsTextWriter()) { debug.WriteLine("Start building Sqlite database schema"); debug.WriteLine("*************************************"); using (var session = sessionFactory.OpenSession()) new SchemaExport(_configuration).Execute(false, true, false, session.Connection, debug); debug.WriteLine("*************************************"); debug.WriteLine("Sqlite database schema build complete"); debug.WriteLine(); } return(sessionFactory); }
static ISessionFactory buildSessionFactoryAndExportSchema() { // ReSharper disable once PossibleNullReferenceException // ReSharper disable once AssignNullToNotNullAttribute var sessionFactory = Fluently.Configure(new Configuration()) .Database(SQLiteConfiguration.Standard .InMemory() .Provider<SqliteInMemoryDriverConnectionProvider>() .ShowSql() .FormatSql() .Raw(Environment.GenerateStatistics, "true")) .Mappings(m => m.AutoMappings.Add(AutoMap .Source(Types.FromAssemblies(Assembly.GetExecutingAssembly()) .Where(t => t.Namespace.StartsWith(typeof(NHibernateContext).Namespace) && t.InheritsOrImplements(typeof(IdentityFieldProvider<,>)))) .IgnoreBase(typeof(IdentityFieldProvider<,>)) .Conventions.AddAssembly(typeof(AbbreviationAttribute).Assembly) .UseOverridesFromAssembly(Assembly.GetExecutingAssembly()))) .Diagnostics(x => x.Enable().OutputToConsole()) .ExposeConfiguration(x => { new SqliteRemapper().Remap(x); _configuration = x; }) .BuildSessionFactory(); using (var debug = new DiagnosticsTextWriter()) { debug.WriteLine("Start building Sqlite database schema"); debug.WriteLine("*************************************"); using (var session = sessionFactory.OpenSession()) new SchemaExport(_configuration).Execute(false, true, false, session.Connection, debug); debug.WriteLine("*************************************"); debug.WriteLine("Sqlite database schema build complete"); debug.WriteLine(); } return sessionFactory; }