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="data source=localhost;initial catalog=testPostgres;persist security info=True;user id=postgres;password=123456;multipleactiveresultsets=True;App=EntityFramework""
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: