4

I'm trying to connect my MVC3 project with a database in Postgres 9.1, I've follow this links: info1, info2, info3 and for the look of it, I only need the string connection in order to create a Controller.

I have the reference to the Mono.Security and Npgsql .dll, I add them to the Assembly

I'm using this connectionString:

<connectionStrings>
    <add name="TestPostgreSQLContext"         
         connectionString="metadata=res://*/Models.TestPostgreSQL.csdl|res://*/Models.TestPostgreSQL.ssdl|res://*/Models.TestPostgreSQL.msl;provider=Npgsql.NpgsqlConnection;provider connection string=&quot;data source=localhost;initial catalog=testPostgres;persist security info=True;user id=postgres;password=123456;multipleactiveresultsets=True;App=EntityFramework&quot;" 
         providerName="Npgsql.NpgsqlConnection"/>
</connectionStrings>

Code markup:

public TestPostgreSQLContext() : base("name=TestPostgreSQLContext", "TestPostgreSQLContext")
{            
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}
public TestPostgreSQLContext(string connectionString) : base(connectionString, "TestPostgreSQLContext")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}
public TestPostgreSQLContext(EntityConnection connection) : base(connection, "TestPostgreSQLContext")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

Here's an more graphical idea: enter image description here

Community
  • 1
  • 1
Luis
  • 5,786
  • 8
  • 43
  • 62

1 Answers1

2

Did you declare Npgsql as a registered provider, in your app's config file or inside machine.config? (see this official Npgsql documentation

ChrisB
  • 2,497
  • 2
  • 24
  • 43
mbarthelemy
  • 12,465
  • 4
  • 41
  • 43