forked from msallin/SQLiteCodeFirst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqliteDatabaseCreator.cs
More file actions
39 lines (36 loc) · 1.26 KB
/
Copy pathSqliteDatabaseCreator.cs
File metadata and controls
39 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using SQLite.CodeFirst.Builder;
using SQLite.CodeFirst.Statement;
namespace SQLite.CodeFirst
{
/// <summary>
/// Creates a SQLite-Database based on a Entity Framework <see cref="Database"/> and <see cref="DbModel"/>.
/// This creator can be used standalone or within an initializer.
/// </summary>
public class SqliteDatabaseCreator
{
private readonly Database db;
private readonly DbModel model;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteDatabaseCreator"/> class.
/// </summary>
/// <param name="db">The database.</param>
/// <param name="model">The model.</param>
public SqliteDatabaseCreator(Database db, DbModel model)
{
this.db = db;
this.model = model;
}
/// <summary>
/// Creates the SQLite-Database.
/// </summary>
public void Create()
{
IStatementBuilder<CreateDatabaseStatement> statementBuilder = new CreateDatabaseStatementBuilder(model.StoreModel);
IStatement statement = statementBuilder.BuildStatement();
string sql = statement.CreateStatement();
db.ExecuteSqlCommand(sql);
}
}
}