没有为ADO.NET提供程序找到实体框架提供程序

时间:2014-06-15 10:09:36

标签: c# wcf app-config entity-framework-6

我一直在尝试使用WCF将一些数据插入到northwind中。我无法弄清楚为什么找不到提供商。

该服务已安装EF6。

以下是我的配置文件的片段:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="northwindEntities" connectionString="metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=northwind;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="OrdersEndPoint" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8080/OrdersHelper" binding="basicHttpBinding" bindingConfiguration="OrdersEndPoint" contract="ServiceReference.IOrdersHelper" name="OrdersEndPoint" />
    </client>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

DBContext类:

public partial class northwindEntities : DbContext
    {
        public northwindEntities()
            : base("name=northwindEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

遵循实体属性和存储过程

2 个答案:

答案 0 :(得分:0)

无法相信我没有早点看到它......我的服务和消费者都安装了不同的EF版本。问题解决了。

答案 1 :(得分:-1)

这是您的Web.config文件

   <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>  
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="OrdersEndPoint" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:8080/OrdersHelper" binding="basicHttpBinding" bindingConfiguration="OrdersEndPoint" contract="ServiceReference.IOrdersHelper" name="OrdersEndPoint" />
        </client>
      </system.serviceModel>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>


    <connectionStrings>
        <add name="northwindEntities" connectionString="metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=northwind;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>


    </configuration>

您的DbContext类应如下所示

public partial class northwindEntities : DbContext
    {
        public northwindEntities()
            : base("northwindEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }