加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:26:38 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的MVC3项目与Postgres 9.1中的数据库连接,我遵循以下链接: info1,info2,info3,为了看起来,我只需要字符串连接即可创建一个Controller. 我有对Mono.Security和Npgsql .dll的引用,我将它们添加到Assembly中 我正在使用此connectionString: con
我正在尝试将我的MVC3项目与Postgres 9.1中的数据库连接,我遵循以下链接: info1,info2,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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读