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
+30-17Lines changed: 30 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,17 @@
7
7
Creates a [SQLite Database](https://sqlite.org/) from Code, using [Entity Framework](https://msdn.microsoft.com/en-us/data/ef.aspx) CodeFirst.
8
8
9
9
## Support the project <ahref="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ARTMHALNW4VC6&lc=CH&item_name=SQLite%2eCodeFirst&item_number=sqlitecodefirst¤cy_code=CHF&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"title="Donate to this project using Paypal"><imgsrc="https://camo.githubusercontent.com/11b2f47d7b4af17ef3a803f57c37de3ac82ac039/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667"alt="PayPal donate button"data-canonical-src="https://img.shields.io/badge/paypal-donate-yellow.svg"style="max-width:100%;"></a>
10
+
10
11
To support this project you can: *star the repository*, report bugs/request features by creating new issues, write code and create PRs or donate.
11
12
Especially if you use it for a commercial project, a donation is welcome.
12
-
If you need a specific feature for a commercial project, I am glad to offer a paid implementation.
13
-
13
+
If you need a specific feature for a commercial project, I am glad to offer a paid implementation.
14
14
15
15
## Features
16
-
This Project ships several `IDbInitializer` classes. These create new SQLite Databases based on your model/code.
16
+
17
+
This project ships several `IDbInitializer` classes. These create new SQLite Databases based on your model/code.
17
18
18
19
The following features are supported:
20
+
19
21
- Tables from classes (supported annotations: `Table`)
- PrimaryKey constraint (`Key` annotation, key composites are supported)
@@ -32,21 +34,24 @@ Either get the assembly from the latest [GitHub Release Page](https://github.com
32
34
33
35
The project is built to target .NET framework versions 4.0 and 4.5.
34
36
You can use the SQLite CodeFirst in projects that target the following frameworks:
35
-
- .NET 4.0 (use net40)
36
-
- .NET 4.5 (use net45)
37
-
- .NET 4.5.1 (use net45)
38
-
- .NET 4.5.2 (use net45)
39
-
- .NET 4.6 (use net45)
40
-
- .NET 4.6.1 (use net45)
41
-
- .NET 4.6.2 (use net45)
42
-
- .NET 4.7 (use net45)
43
-
- .NET 4.7.1 (use net45)
44
-
- .NET 4.7.2 (use net45)
37
+
38
+
- .NET 4.0 (uses net40)
39
+
- .NET 4.5 (uses net45)
40
+
- .NET 4.5.1 (uses net45)
41
+
- .NET 4.5.2 (uses net45)
42
+
- .NET 4.6 (uses net45)
43
+
- .NET 4.6.1 (uses net45)
44
+
- .NET 4.6.2 (uses net45)
45
+
- .NET 4.7 (uses net45)
46
+
- .NET 4.7.1 (uses net45)
47
+
- .NET 4.7.2 (uses net45)
45
48
- .NET 4.8 (uses net45)
46
49
47
50
## How to use
51
+
48
52
The functionality is exposed by using implementations of the `IDbInitializer<>` interface.
49
53
Depending on your need, you can choose from the following initializers:
54
+
50
55
- SqliteCreateDatabaseIfNotExists
51
56
- SqliteDropCreateDatabaseAlways
52
57
- SqliteDropCreateDatabaseWhenModelChanges
@@ -57,6 +62,7 @@ Or for even more control, use the `SqliteSqlGenerator` (implements `ISqlGenerato
57
62
When you want to let the Entity Framework create database if it does not exist, just set `SqliteDropCreateDatabaseAlways<>` or `SqliteCreateDatabaseIfNotExists<>` as your `IDbInitializer<>`.
58
63
59
64
### Initializer Sample
65
+
60
66
```csharp
61
67
publicclassMyDbContext : DbContext
62
68
{
@@ -70,13 +76,15 @@ public class MyDbContext : DbContext
70
76
}
71
77
}
72
78
```
79
+
73
80
Notice that the `SqliteDropCreateDatabaseWhenModelChanges<>` initializer will create a additional table in your database.
74
81
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
75
-
`IHistory` interface and pass the type of your entity as parameter in the to the constructor from the initializer.
82
+
`IHistory` interface and pass the type of your entity as parameter in the to the constructor from the initializer.
76
83
77
84
In a more advanced scenario, you may want to populate some core- or test-data after the database was created.
78
85
To do this, inherit from `SqliteDropCreateDatabaseAlways<>`, `SqliteCreateDatabaseIfNotExists<>` or `SqliteDropCreateDatabaseWhenModelChanges<>` and override the `Seed(MyDbContext context)` function.
79
86
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.
@@ -91,6 +99,7 @@ public class MyDbContextInitializer : SqliteDropCreateDatabaseAlways<MyDbContext
91
99
```
92
100
93
101
### SqliteDatabaseCreator Sample
102
+
94
103
```csharp
95
104
publicclassMyContext : DbContext
96
105
{
@@ -104,6 +113,7 @@ public class MyContext : DbContext
104
113
```
105
114
106
115
### SqliteSqlGenerator Sample
116
+
107
117
```csharp
108
118
publicclassMyContext : DbContext
109
119
{
@@ -117,15 +127,18 @@ public class MyContext : DbContext
117
127
```
118
128
119
129
## Structure
120
-
I tried to write the code in a extensible way.
130
+
131
+
The code is written in an extensible way.
121
132
The logic is divided into two main parts, Builder and Statement.
122
133
The Builder knows how to translate the EdmModel into statements where a statement class creates the SQLite-DDL-Code.
123
134
The structure of the statements is influenced by the [SQLite Language Specification](https://www.sqlite.org/lang.html).
124
135
You will find an extensive usage of the composite pattern.
125
136
126
137
## Hints
138
+
127
139
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.
128
-
In this case please check the following issue: https://github.com/msallin/SQLiteCodeFirst/issues/13.
140
+
In this case please check the following issue: <https://github.com/msallin/SQLiteCodeFirst/issues/13.>
129
141
130
142
## Recognition
131
-
I started with the [code](https://gist.github.com/flaub/1968486e1b3f2b9fddaf) from [flaub](https://github.com/flaub).
143
+
144
+
I started with the [code](https://gist.github.com/flaub/1968486e1b3f2b9fddaf) from [flaub](https://github.com/flaub).
0 commit comments