In my project, I am trying to use Entity Framework with PostgreSql. But I can not connect to my database. I get no mistake, she just gets stuck. I think something is wrong with mine app.config, but I can’t find out what.
App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
<providers>
<provider invariantName="Npgsql"
type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="Entities"
connectionString="server=localhost;user id=postgres;password=4321;database=postgis"
providerName="Npgsql" />
</connectionStrings>
</configuration>
DbContext:
public class Entities : DbContext
{
public Entities() : base("Entities")
{
}
}
mycode.cs
using (var db = new Entities())
{
}
EDIT:
I get the following error:
"Entity Framework provider type" Npgsql.NpgsqlServices, Npgsql.EntityFramework "registered in the application configuration file for the ADO.NET provider with the invariant name" Npgsql "cannot be loaded. Make sure that the name corresponding to the assembly is used , and assembly is available for the running application.