Specifying database connection string for EntityFramework6.Npgsql - Code First

.net c# entity-framework-6 npgsql postgresql


I have an issue regarding the .NET postgreSQL provider package EntityFramework6.Npgsql. I have installed the following packages: EntityFramework 6.0.0, EntityFramework6.NpgSql 3.1.1, Npgsql 3.1.0.

Currently I have just started a WPF project so I'm using a simple standard DbContext and it looks like this:

public class TimetrackerDbContext : DbContext
    public TimetrackerDbContext()
        : base("name=DbConnection")

    protected override void OnModelCreating(DbModelBuilder modelBuilder)

    public virtual DbSet<MyEntity> MyEntities { get; set; }

public class MyEntity
    public int Id { get; set; }
    public string Name { get; set; }

Now in my App.config file I specify the connection string. I've been trying to use this connection:

<add name="DbConnection"
   connectionString="User ID=xxx;Password=xxx;Host=xxx;Port=5432;Database=xxx;Pooling=true;"
   providerName="System.Data.EntityClient" /> 

But when I run enable-migrations -contexttypename MyDbContext in the PM Console I get the following error:

Keyword not supported: 'user id'.

I tried specyfying the metadata, provider connection string but it also threw errors and it does not make much sense to use it in Code First. In case somebody it could be useful here's my whole App.config:

<?xml version="1.0" encoding="utf-8"?>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="v11.0" />
      <!--<provider invariantName="System.Data.SqlClient"     type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion=""         />
     <add name="DbConnection"
   connectionString="User ID=xxx;Password=xxx;Host=xxx;Port=5432;Database=xxx;Pooling=true;"
   providerName="System.Data.EntityClient" />
7/22/2017 10:18:57 PM

Accepted Answer

The providerName of your connection string System.Data.EntityClient is for Database First (edmx) type connections where the actual provider is encoded in the connectionString value.

For Code First connections, the providerName should match the invariantName from the providers section. In your case, replace



7/23/2017 10:55:06 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow