Skip to content

Commit dd8d954

Browse files
committed
#139: Deleted unnecessary transaction creation.
1 parent a5f2217 commit dd8d954

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

SQLite.CodeFirst/Public/DbInitializers/SqliteInitializerBase.cs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public abstract class SqliteInitializerBase<TContext> : IDatabaseInitializer<TCo
2626
{
2727
protected SqliteInitializerBase(DbModelBuilder modelBuilder)
2828
{
29-
if (modelBuilder == null)
30-
{
31-
throw new ArgumentNullException("modelBuilder");
32-
}
33-
34-
ModelBuilder = modelBuilder;
29+
ModelBuilder = modelBuilder ?? throw new ArgumentNullException(nameof(modelBuilder));
3530

3631
// This convention will crash the SQLite Provider before "InitializeDatabase" gets called.
3732
// See https://github.com/msallin/SQLiteCodeFirst/issues/7 for details.
@@ -76,35 +71,11 @@ public virtual void InitializeDatabase(TContext context)
7671
string dbFile = GetDatabasePathFromContext(context);
7772
InMemoryAwareFile.CreateDirectory(dbFile);
7873

79-
using (DbContextTransaction transaction = context.Database.BeginTransaction())
80-
{
81-
try
82-
{
83-
var sqliteDatabaseCreator = new SqliteDatabaseCreator();
84-
sqliteDatabaseCreator.Create(context.Database, model);
85-
transaction.Commit();
86-
}
87-
catch (Exception)
88-
{
89-
transaction.Rollback();
90-
throw;
91-
}
92-
}
74+
var sqliteDatabaseCreator = new SqliteDatabaseCreator();
75+
sqliteDatabaseCreator.Create(context.Database, model);
9376

94-
using (DbContextTransaction transaction = context.Database.BeginTransaction())
95-
{
96-
try
97-
{
98-
Seed(context);
99-
context.SaveChanges();
100-
transaction.Commit();
101-
}
102-
catch (Exception)
103-
{
104-
transaction.Rollback();
105-
throw;
106-
}
107-
}
77+
Seed(context);
78+
context.SaveChanges();
10879
}
10980

11081
/// <summary>

SQLite.CodeFirst/Public/SqliteDatabaseCreator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace SQLite.CodeFirst
88
/// <summary>
99
/// Creates a SQLite-Database based on a Entity Framework <see cref="Database"/> and <see cref="DbModel"/>.
1010
/// This creator can be used standalone or within an initializer.
11+
/// <remark>
12+
/// The generated DDL-SQL will be executed together as one statement.
13+
/// If there is a open transaction on the Database, the statement will be executed within this transaction.
14+
/// Otherwise it will be executed within a own transaction. In anyway the atomicity is guaranteed.
15+
/// </remark>
1116
/// </summary>
1217
public class SqliteDatabaseCreator : IDatabaseCreator
1318
{

0 commit comments

Comments
 (0)