无法使用实体框架找到或加载 Npgsql [英] Unable to find or load Npgsql with Entity Framework

查看:68
本文介绍了无法使用实体框架找到或加载 Npgsql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全迷路了.在 Visual Studio 2015 中,我创建了一个 WCF Library Service 项目并定义了服务和服务接口.

I am totally lost. In Visual Studio 2015, I created a WCF Library Service project and defined the service and service interface.

EntityFramework、EntityFramework.SqlServer、EntityFramework6.Npgsql 和 Npgsql 与 NuGet 控制台一起安装:

EntityFramework, EntityFramework.SqlServer, EntityFramework6.Npgsql, and Npgsql was installed with the NuGet console:

  • PM> 安装包 EntityFramework6.Npgsql -Version 3.0.5

将库服务设置为启动然后正确启动调试(f5)阅读可用的程序.但是,在测试任何程序时WcfSvcHost,我收到以下错误:

Setting the library service as startup then starting debug (f5) correctly read the available procedures. However, upon testing any procedure in the WcfSvcHost, I get the following error:

具有不变名称Npgsql"的 ADO.NET 提供程序要么不是在机器或应用程序配置文件中注册,或者不能加载.有关详细信息,请参阅内部异常.

The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

我做错了什么?

这是 App.config 文件:

Here is the App.config file:

<?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=&quot;Database=chaos;Host=localhost;Password=yuyuyu;Username=ooosos&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

有人可以帮忙吗?我完全迷路了.

Can someone please help? I am totally lost.

TIA

推荐答案

问题已解决.我忽略添加:

Problem solved. I neglected to add:

<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 支持 (DDEX)

这篇关于无法使用实体框架找到或加载 Npgsql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆