时间:2021-07-01 10:21:17 帮助过:8人阅读
项目采用codefirst的方式,但是在搭建项目的时候,总是遇到这个错。
我的步骤如下
1、安装entityframework6
打开 Package Manage Console,输入命令 Install-Package EntityFramework;
2、安装npgsql 的entityframework支持
命令 Install-Package EntityFramework6.Npgsql
3、安装 npgsql
命令 Install-Package Npgsql
配置文件代码示例
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql"></remove>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="TestDbContext" connectionString="Server=localhost;Database=test; User Id=dba;Password=12345678;" providerName="Npgsql" />
</connectionStrings>
但不知道为什么,还是会报错!
后来,我下是不是包的安装顺序搞错了!!就把上面的2和3换了一下!成功!!!
哎,也是醉了!这个小问题,都纠缠了这么久!写代码需要更加小心啊!
EF+postgresql中的一些问题
标签: