我们正在使用的EntityFramework 6 $ C C首先$。我们有一个控制台应用程序,有没有提到的EntityFramework但读取它的App.config的连接字符串。它调用组件传递连接字符串作为参数的DatabaseInitializationUtilities。
We are using EntityFramework 6 with Code First. We have a console app that has no reference to EntityFramework but reads the connection string from its App.config. It calls the DatabaseInitializationUtilities assembly passing the connection string as a parameter.
DatabaseInitializationUtilities具有参照EF6(的EntityFramework和EntityFramework.SqlServer)。它的App.config中是这样的:
DatabaseInitializationUtilities has the reference to EF6 (EntityFramework and EntityFramework.SqlServer). Its App.config is this:
<?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试图运行一个脚本
When execution reaches a line where DatabaseInitializationUtilities attempts to run a script
context.Database.ExecuteSqlCommand(script.ScriptText)
错误被抛出:
the error is thrown:
没有实体框架提供发现ADO.NET提供与固定名称System.Data.SqlClient的。确保供应商是注册在应用程序配置文件的EntityFramework部分。请参阅http://go.microsoft.com/fwlink/?LinkId=260882了解更多信息。
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
我相信,补救正是我在我的配置文件,所以我不明白这个问题。
I believe the remedy is exactly what I have in my config file, so I don't understand the problem.
注:ReSharper的是bluelining节点和报告 元素的EntityFramework有一个无效的子元素供应商,但部分被的NuGet当我安装EF6注入。
NOTE: Resharper is bluelining the node and reporting "The element 'EntityFramework' has an invalid child element 'providers'. However, the section was injected by NuGet when I installed EF6.
任何想法?
您需要做一个参考,所以它会在书房应用程序路径进行复制。因为稍后将在运行时被引用。所以,你不需要复制任何文件。
You need to make a reference, so it will be copied in den application path. Because later it will be referenced in runtime. So you don't need to copy any files.
private volatile Type _dependency;
public MyClass()
{
_dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}