C# 在单独的项目中访问实体模型时出错

C# 在单独的项目中访问实体模型时出错,c#,entity-framework,C#,Entity Framework,我有两个项目,其中一个包含实体模型并充当DAL,另一个使用该模型并实现应用程序逻辑 模型是一个类库项目,应用程序是一个windows窗体项目 使用以下项目的app.config文件,并在forms项目中引用System.Data.Entity,当我运行WinForms应用程序时,出现以下错误: 其他信息:无法加载在ADO.NET提供程序的应用程序配置文件中注册的实体框架提供程序类型“System.Data.Entity.SqlServer.SqlProviderServices,EntityFr

我有两个项目,其中一个包含实体模型并充当DAL,另一个使用该模型并实现应用程序逻辑

模型是一个类库项目,应用程序是一个windows窗体项目

使用以下项目的app.config文件,并在forms项目中引用System.Data.Entity,当我运行WinForms应用程序时,出现以下错误:

其他信息:无法加载在ADO.NET提供程序的应用程序配置文件中注册的实体框架提供程序类型“System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer”,其固定名称为“System.Data.SqlClient”。确保使用了程序集限定名称,并且该程序集可供正在运行的应用程序使用

你认为问题出在哪里

DAL项目的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" />
  </configSections>
  <connectionStrings>
    <add name="ProviderInterfaceContext" connectionString="metadata=res://*/ProviderInterfaceModel.csdl|res://*/ProviderInterfaceModel.ssdl|res://*/ProviderInterfaceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.2.12;initial catalog=ProviderInterface;user id=--;password=---;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.serviceModel>
    <client>
      <endpoint address=""
          binding="basicHttpBinding"
          contract="PrizeServiceSoap" name="PrizeServiceSoap" />
    </client>
  </system.serviceModel>
</configuration>
<?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" />
  </configSections>
  <connectionStrings>
    <add name="ProviderInterfaceContext" connectionString="metadata=res://*/ProviderInterfaceModel.csdl|res://*/ProviderInterfaceModel.ssdl|res://*/ProviderInterfaceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.2.12;initial catalog=ProviderInterface;user id=---;password=----;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

WinForms 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" />
  </configSections>
  <connectionStrings>
    <add name="ProviderInterfaceContext" connectionString="metadata=res://*/ProviderInterfaceModel.csdl|res://*/ProviderInterfaceModel.ssdl|res://*/ProviderInterfaceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.2.12;initial catalog=ProviderInterface;user id=--;password=---;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.serviceModel>
    <client>
      <endpoint address=""
          binding="basicHttpBinding"
          contract="PrizeServiceSoap" name="PrizeServiceSoap" />
    </client>
  </system.serviceModel>
</configuration>
<?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" />
  </configSections>
  <connectionStrings>
    <add name="ProviderInterfaceContext" connectionString="metadata=res://*/ProviderInterfaceModel.csdl|res://*/ProviderInterfaceModel.ssdl|res://*/ProviderInterfaceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.2.12;initial catalog=ProviderInterface;user id=---;password=----;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

已修复

添加了对EntityFramework 6.0和EntityFramework.SqlServer的引用,现在一切正常