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
Configuration for an Entity Framework application can be specified in a config file (app.config/web.config) or through code. The latter is known as code-based configuration.
12
9
13
-
### Code-based ###
10
+
### Code-based
14
11
15
12
To use Entity Framework with Npgsql, define a class that inherits from `DbConfiguration` in the same assembly as your class inheriting `DbContext`. Ensure that you configure provider services, a provider factory, a default connection factory as shown below:
16
13
@@ -35,7 +32,7 @@ class NpgSqlConfiguration : DbConfiguration
35
32
}
36
33
```
37
34
38
-
### Config file ###
35
+
### Config file
39
36
40
37
When installing `EntityFramework6.Npgsql` nuget package, the relevant sections in `App.config` / `Web.config` are usually automatically updated. You typically only have to add your `connectionString` with the correct `providerName`.
41
38
@@ -59,7 +56,7 @@ When installing `EntityFramework6.Npgsql` nuget package, the relevant sections i
59
56
</configuration>
60
57
```
61
58
62
-
## Guid Support ##
59
+
## Guid Support
63
60
64
61
Npgsql EF migrations support uses `uuid_generate_v4()` function to generate guids.
65
62
In order to have access to this function, you have to install the extension uuid-ossp through the following command:
@@ -78,7 +75,7 @@ If the database is being created by Npgsql Migrations, you will need to
78
75
[run the `create extension` command in the `template1` database](http://stackoverflow.com/a/11584751).
79
76
This way, when the new database is created, the extension will be installed already.
80
77
81
-
## Optimistic Concurrency ##
78
+
## Optimistic Concurrency
82
79
83
80
EntityFramework supports [optimistic concurrency](https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), through the [system column `xmin`](https://www.postgresql.org/docs/current/ddl-system-columns.html). To use this column as the concurrency token, some [customization is needed](https://github.com/npgsql/EntityFramework6.Npgsql/issues/8). The following code will setup `Department.Version` to map to `xmin`, while the `SqlGenerator` will generate `CREATE/ALTER TABLE` statements omitting system columns.
84
81
@@ -126,15 +123,15 @@ public class SqlGenerator : NpgsqlMigrationSqlGenerator
126
123
}
127
124
```
128
125
129
-
## Template Database ##
126
+
## Template Database
130
127
131
128
When the Entity Framework 6 provider creates a database, it issues a simple `CREATE DATABASE` command.
132
129
In PostgreSQL, this implicitly uses `template1` as the template - anything existing in `template1` will
133
130
be copied to your new database. If you wish to change the database used as a template, you can specify
134
131
the `EF Template Database` connection string parameter. For more info see the
You can use [an Entity Framework 6 IDbCommandInterceptor](https://msdn.microsoft.com/library/dn469464(v=vs.113).aspx) to wrap the `DataReader` instance returned by Npgsql when Entity Framework executes queries. This is possible using a ```DbConfiguration``` class.
0 commit comments