微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 无法检索连接MVC3 EF与Postgres 9.1的元数据

我正在尝试将我的MVC3项目与Postgres 9.1中的数据库连接,我遵循以下链接info1,@L_404_1@,info3,为了看起来,我只需要字符串连接即可创建一个Controller.

我有对Mono.Security和Npgsql .dll的引用,我将它们添加到Assembly中

我正在使用此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>

代码标记

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();
}

这是一个更加图形化的想法:

解决方法

您是否在应用程序的配置文件或machine.config内声明了Npgsql作为注册提供程序? (见 this official Npgsql documentation

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐