NET提供程序的实体框架提供程序

NET提供程序的实体框架提供程序

本文介绍了找不到具有不变名称“System.Data.SqlClient”的ADO.NET提供程序的实体框架提供程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用具有代码优先级的EntityFramework 6。我们有一个没有引用EntityFramework的控制台应用程序,但从App.config读取连接字符串。它调用DatabaseInitializationUtilities程序集作为参数传递连接字符串。



DatabaseInitializationUtilities参考了EF6(EntityFramework和EntityFramework.SqlServer)。它的App.config是这样的:

 <?xml version =1.0encoding =utf-8?> 
< configuration>
< configSections>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
< / configSections>
< system.serviceModel>
< bindings>
< basicHttpBinding>
< binding name =BasicHttpBinding_IAuthentication/>
< / basicHttpBinding>
< / bindings>
< client>
< endpoint address =http://localhost/SecurityServices/Authentication.svcbinding =basicHttpBindingbindingConfiguration =BasicHttpBinding_IAuthenticationcontract =SecurityService.IAuthenticationname =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.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>
< / configuration>

当执行到达DatabaseInitializationUtilities尝试运行脚本的行时

  context.Database.ExecuteSqlCommand(script.ScriptText)

错误被抛出:

我相信补救办法正是我在配置文件中所做的,所以我不明白这个问题。 / p>

注意:Resharper是bluelining节点并报告
元素EntityFramework有一个无效的子元素'providers',但是该部分是由NuGet注入的当我安装了EF6。



任何想法?

解决方案

创建一个引用,所以它将被复制到调试文件夹中,所以后来可以在运行时访问。



不要复制任何文件,只需创建此引用:

  private volatile Type _dependency; 

public MyClass()
{
_dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}


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 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>

When execution reaches a line where DatabaseInitializationUtilities attempts to run a script

context.Database.ExecuteSqlCommand(script.ScriptText)

the error is thrown:

I believe the remedy is exactly what I have in my config file, so I don't understand the problem.

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.

Any ideas?

解决方案

You need to create a reference, so it will be copied in the debug folder. So later it can accessed in runtime.

Don't to copy any files, just create this reference:

private volatile Type _dependency;

public MyClass()
{
    _dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}

这篇关于找不到具有不变名称“System.Data.SqlClient”的ADO.NET提供程序的实体框架提供程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:55