using System; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Diagnostics; namespace SQLite.CodeFirst { /// /// Creates a SQLite-Database based on a Entity Framework and . /// This creator can be used standalone or within an initializer. /// /// The generated DDL-SQL will be executed together as one statement. /// If there is a open transaction on the Database, the statement will be executed within this transaction. /// Otherwise it will be executed within a own transaction. In anyway the atomicity is guaranteed. /// /// public class SqliteDatabaseCreator : IDatabaseCreator { public SqliteDatabaseCreator(Collation defaultCollation = null) { DefaultCollation = defaultCollation; } public Collation DefaultCollation { get; } /// /// Creates the SQLite-Database. /// public void Create(Database db, DbModel model) { if (db == null) throw new ArgumentNullException("db"); if (model == null) throw new ArgumentNullException("model"); var sqliteSqlGenerator = new SqliteSqlGenerator(DefaultCollation); string sql = sqliteSqlGenerator.Generate(model.StoreModel); Debug.Write(sql); db.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction, sql); } } }