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>
当执行到DatabaseInitializationUtilities尝试运行脚本的代码行时
context.Database.ExecuteSqlCommand(script.ScriptText)
错误信息:
没有找到与固定名称 'System.Data.SqlClient' 的 ADO.NET 提供程序匹配的 Entity Framework 提供程序。请确保在应用程序配置文件的 'entityFramework' 部分中注册了提供程序。有关更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=260882。
我相信解决方法就是我配置文件中的内容,所以我不理解这个问题。
注意:Resharper 在节点上标出蓝线并报告“元素 'EntityFramework' 具有无效的子元素 'providers'。然而,当我安装 EF6 时,该部分被 NuGet 注入。
有什么想法吗?