/// <summary> /// Initialize the database for the given context. /// Generates the SQLite-DDL from the model and executs it against the database. /// After that the <see cref="Seed"/> method is executed. /// All actions are be executed in transactions. /// </summary> /// <param name="context">The context. </param> public virtual void InitializeDatabase(TContext context) { var model = modelBuilder.Build(context.Database.Connection); using (var transaction = context.Database.BeginTransaction()) { try { var sqliteDatabaseCreator = new SqliteDatabaseCreator(context.Database, model); sqliteDatabaseCreator.Create(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } using (var transaction = context.Database.BeginTransaction()) { try { Seed(context); context.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } }
/// <summary> /// Initialize the database for the given context. /// Generates the SQLite-DDL from the model and executs it against the database. /// After that the <see cref="Seed" /> method is executed. /// All actions are be executed in transactions. /// </summary> /// <param name="context">The context. </param> public virtual void InitializeDatabase(TContext context) { DbModel model = ModelBuilder.Build(context.Database.Connection); string dbFile = GetDatabasePathFromContext(context); InMemoryAwareFile.CreateDirectory(dbFile); var sqliteDatabaseCreator = new SqliteDatabaseCreator(); sqliteDatabaseCreator.Create(context.Database, model); Seed(context); context.SaveChanges(); }
/// <summary> /// Initialize the database for the given context. /// Generates the SQLite-DDL from the model and executs it against the database. /// After that the <see cref="Seed"/> method is executed. /// All actions are be executed in transactions. /// </summary> /// <param name="context">The context. </param> public virtual void InitializeDatabase(TContext context) { var model = ModelBuilder.Build(context.Database.Connection); var dbFile = GetDatabasePathFromContext(context); if (!IsMemoryDb(dbFile)) { var dbFileInfo = new FileInfo(dbFile); dbFileInfo.Directory.Create(); } using (var transaction = context.Database.BeginTransaction()) { try { var sqliteDatabaseCreator = new SqliteDatabaseCreator(); sqliteDatabaseCreator.Create(context.Database, model); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } using (var transaction = context.Database.BeginTransaction()) { try { Seed(context); context.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } }
/// <summary> /// Initialize the database for the given context. /// Generates the SQLite-DDL from the model and executs it against the database. /// After that the <see cref="Seed" /> method is executed. /// All actions are be executed in transactions. /// </summary> /// <param name="context">The context. </param> public virtual void InitializeDatabase(TContext context) { DbModel model = ModelBuilder.Build(context.Database.Connection); string dbFile = GetDatabasePathFromContext(context); InMemoryAwareFile.CreateDirectory(dbFile); using (DbContextTransaction transaction = context.Database.BeginTransaction()) { try { var sqliteDatabaseCreator = new SqliteDatabaseCreator(); sqliteDatabaseCreator.Create(context.Database, model); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } using (DbContextTransaction transaction = context.Database.BeginTransaction()) { try { Seed(context); context.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } }