I have already seen threads discussing the use of Entity Framework and PostgreSQL with official instructions. Those instructions need to run gacutil
for every install which is not so handy for deployment purposes.
What I want to do here is passing PostgreSQL connection directly to the DbContext
constructor. This is enough for me because I am going to use CodeFirst
without designer. This is what I do:
public class Context : DbContext
{
Context(System.Data.Common.DbConnection connection)
: base(connection, true)
{
}
public static Context CreateContext()
{
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=********;Database=xxx;");
conn.Open();
return new Context(conn);
}
}
But using this method I get a NotSupportedException
with message:
Unable to determine the provider name for connection of type 'Npgsql.NpgsqlConnection'.
What should I do?