You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-1Lines changed: 41 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,18 @@ You can use the SQLite CodeFirst in projects that target the following framework
42
42
- .NET 4.6.1 (use net45)
43
43
44
44
## How to use
45
+
The functionality is exposed by using implementations of the `IDbInitializer<>` interface.
46
+
Depending on your need, you can choose from the following initializers:
47
+
- SqliteCreateDatabaseIfNotExists
48
+
- SqliteDropCreateDatabaseAlways
49
+
- SqliteDropCreateDatabaseWhenModelChanges
50
+
51
+
If you want to have more control, you can use the `SqliteDatabaseCreator` (implements `IDatabaseCreator`) which lets you control the creation of the SQLite database.
52
+
Or for even more control, use the `SqliteSqlGenerator` (implements `ISqlGenerator`), which lets you generate the SQL code based on your `EdmModel`.
53
+
45
54
When you want to let the Entity Framework create database if it does not exist, just set `SqliteDropCreateDatabaseAlways<>` or `SqliteCreateDatabaseIfNotExists<>` as your `IDbInitializer<>`.
55
+
56
+
### Initializer Sample
46
57
```csharp
47
58
publicclassMyDbContext : DbContext
48
59
{
@@ -56,9 +67,12 @@ public class MyDbContext : DbContext
56
67
}
57
68
}
58
69
```
70
+
Notice that the `SqliteDropCreateDatabaseWhenModelChanges<>` initializer will create a additional table in your database.
71
+
This table is used to store some information to detect model changes. If you want to use a own entity/table you can implement the
72
+
`IHistory` interface and pass the type of your entity as parameter in the to the constructor from the initializer.
59
73
60
74
In a more advanced scenario, you may want to populate some core- or test-data after the database was created.
61
-
To do this, inherit from `SqliteDropCreateDatabaseAlways<>`or `SqliteCreateDatabaseIfNotExists<>` and override the `Seed(MyDbContext context)` function.
75
+
To do this, inherit from `SqliteDropCreateDatabaseAlways<>`, `SqliteCreateDatabaseIfNotExists<>`or `SqliteDropCreateDatabaseWhenModelChanges<>` and override the `Seed(MyDbContext context)` function.
62
76
This function will be called in a transaction once the database was created. This function is only executed if a new database was successfully created.
If you try to reinstall the NuGet-Packages (e.g. if you want to downgrade to .NET 4.0), the app.config will be overwritten and you may getting an exception when you try to run the console project.
78
118
In this case please check the following issue: https://github.com/msallin/SQLiteCodeFirst/issues/13.
0 commit comments