The MVC-based WEBAPI is needed to build a service interface, where data is stored in the PostgreSQL database and encountered many problems during use. Take a look at the record:
(1) System.IO.FileLoadException: Failed to load file or assembly "Npgsql, version=3.1.2.0, Culture=neutral, publickeytoken= 5d8b90d52f46fda7 "or one of its dependencies. The found assembly manifest definition does not match the assembly reference. (Exception from hresult:0x80131040)
The project is Codefirst, but it's always a mistake when it comes to building a project.
My steps are as follows
1, installation Entityframework6
Open the Package Manage Console and enter the command install-package entityframework;
2, installation of Npgsql entityframework support
Command Install-package Entityframework6.npgsql
3, Installation Npgsql
Command Install-package Npgsql
Sample configuration file Code
<entityFramework> <defaultconnectionfactory type= " System.Data.Entity.Infrastructure.SqlConnectionFactory, entityframework "/> <providers> <provider Inva Riantname= "System.Data.SqlClient" type= "System.Data.Entity.SqlServer.SqlProviderServices, Entityframework.sqlserver "/> <provider invariantname=" Npgsql "type=" npgsql.npgsqlservices, Entityframework6.npgsql "/> </providers> </entityFramework> <system.data> <dbproviderfacto ries> <remove invariant= "Npgsql" ></remove> <add name= "Npgsql Data Provider" invariant= "Npgsql" Description= ". Net Framework Data Provider for Postgresql Server" type= "npgsql.npgsqlfactory, Npgsql"/> </dbprov iderfactories> </system.data> <connectionStrings> <add name= "Testdbcontext" connectionstring= " Server=localhost;database=test; User Id=dba; password=12345678, "providername=" Npgsql "/> </connectionstrings>
But don't know why, still will error!
Later, I was not the package installed in the wrong order!! Just change the top 2 and 3! Success!!!
Hey, it's drunk too! This little problem has been entangled for so long! Writing code needs to be more careful!
Some problems in the Ef+postgresql