无法使用实体框架找到或加载 Npgsql
Posted
技术标签:
【中文标题】无法使用实体框架找到或加载 Npgsql【英文标题】:Unable to find or load Npgsql with Entity Framework 【发布时间】:2016-05-27 07:12:58 【问题描述】:我完全迷路了。在 Visual Studio 2015 中,我创建了一个 WCF 库服务项目并定义了服务和服务接口。
EntityFramework、EntityFramework.SqlServer、EntityFramework6.Npgsql 和 Npgsql 与 NuGet 控制台一起安装:
PM> 安装包 EntityFramework6.Npgsql -Version 3.0.5将库服务设置为启动然后正确启动调试(f5) 阅读可用的程序。然而,在测试任何程序在 WcfSvcHost,我收到以下错误:
具有不变名称“Npgsql”的 ADO.NET 提供程序不是 在机器或应用程序配置文件中注册,或无法注册 加载。有关详细信息,请参阅内部异常。
我做错了什么?
这里是 App.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="NovaMedicalService.MedicalService">
<endpoint address="" binding="basicHttpBinding" contract="NovaMedicalService.IMedicalService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/NovaMedicalService/MedicalService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<connectionStrings>
<add name="chaosEntities" connectionString="metadata=res://*/ChaosModel.csdl|res://*/ChaosModel.ssdl|res://*/ChaosModel.msl;provider=Npgsql;provider connection string="Database=chaos;Host=localhost;Password=yuyuyu;Username=ooosos"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
有人可以帮忙吗?我完全迷路了。
TIA
【问题讨论】:
【参考方案1】:问题解决了。我忽略了补充:
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
(见Visual Studio Support (DDEX)
【讨论】:
那么这个解决方案的解释是什么?【参考方案2】:卸载并重新安装 Npgsql.vsix 解决了这个问题。
【讨论】:
以上是关于无法使用实体框架找到或加载 Npgsql的主要内容,如果未能解决你的问题,请参考以下文章