我们正在使用EntityFramework 6和Code First.我们有一个控制台应用程序,它没有引用EntityFramework但是从其App.config读取连接字符串.它调用DatabaseInitializationUtilities程序集将连接字符串作为参数传递.
DatabaseInitializationUtilities引用了EF6(EntityFramework和EntityFramework.SqlServer).它的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>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAuthentication" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/SecurityServices/Authentication.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAuthentication" contract="SecurityService.IAuthentication" name="BasicHttpBinding_IAuthentication" />
</client>
</system.serviceModel>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Run Code Online (Sandbox Code Playgroud)
执行到达DatabaseInitializationUtilities尝试运行脚本的行时
context.Database.ExecuteSqlCommand(script.ScriptText)
Run Code Online (Sandbox Code Playgroud)
抛出错误:
没有为ADO.NET提供程序找到具有不变名称"System.Data.SqlClient"的实体框架提供程序.确保提供程序已在应用程序配置文件的"entityFramework"部分中注册.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882.
我相信补救措施正是我在配置文件中所拥有的,所以我不明白这个问题.
注意:Resharper使节点变蓝并报告"元素'EntityFramework'具有无效的子元素'提供者'.但是,当我安装EF6时,NuGet会注入该部分.
有任何想法吗?