【发布时间】:2014-02-06 04:22:24
【问题描述】:
我们正在使用带有 Code First 的 EntityFramework 6。我们有一个控制台应用程序,它没有引用 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>
当执行到达 DatabaseInitializationUtilities 尝试运行脚本的行时
context.Database.ExecuteSqlCommand(script.ScriptText)
抛出错误:
找不到具有不变名称“System.Data.SqlClient”的 ADO.NET 提供程序的实体框架提供程序。确保提供程序已在应用程序配置文件的“entityFramework”部分注册。请参阅http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息。
我相信补救措施正是我的配置文件中的内容,所以我不明白这个问题。
注意:Resharper 正在蓝化节点并报告 "元素 'EntityFramework' 的子元素 'providers' 无效。但是,该部分是在我安装 EF6 时由 NuGet 注入的。
有什么想法吗?
【问题讨论】:
-
谢谢。对 [stackoverflow.com/questions/14033193/… 的评论很有帮助。 [1]:stackoverflow.com/questions/14033193/…
-
将 EntityFramework.SqlServer.dll 添加到客户端应用程序并将连接字符串添加到其 app.config 文件中就可以了。现在错误消失了stackoverflow.com/questions/18455747/…
-
在我们的例子中,EF 程序集是 GACed。在这种情况下,您应该在配置文件中使用完整的程序集名称:
标签: c# asp.net .net sql-server entity-framework-6