3
I am trying to make a connection with EF and Postgresql in an Asp.Net Mvc application
I am using the following references
- Entityframework6.Npgsql
- Npgsql 3.1
- .NET Framework 4.5
I have the following classes:
public class Categoria
{
[Key]
public int Id { get; set; }
public int Descricao { get; set; }
public int Status { get; set; }
}
public class MeuNegocioContext : DbContext
{
public DbSet <Categoria> Categorias { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// do not use migration
Database.SetInitializer<MeuNegocioContext>(null);
modelBuilder.Entity<Categoria>().ToTable("Categoria", "public");
}
}
And my Web.Config stays that way http://pastebin.com/QNmSSAyU
<connectionStrings>
<add name="MeuNegocioContext" connectionString="Server=127.0.0.1;Port=5432;Database=meunegocioweb;User Id=postgres;Password=6844866;" providerName="Npgsql" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
However an error occurs when I try to perform the following function
// GET: Categorias
public ActionResult Index()
{
return View(db.Categorias.ToList());
}
An Exception of type 'System.Typeinitializationexception' occurred in Npgsql.dll but was not handled in user code
Additional information: The 'Npgsql.Counters' type initializer triggered an exception.
What would be the problem related to my Webconfig?