Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 未找到具有固定名称的ADO.NET提供程序的实体框架提供程序';System.Data.SqlServerCe.4.0';_Entity Framework_C# 4.0_Sql Server Ce - Fatal编程技术网

Entity framework 未找到具有固定名称的ADO.NET提供程序的实体框架提供程序';System.Data.SqlServerCe.4.0';

Entity framework 未找到具有固定名称的ADO.NET提供程序的实体框架提供程序';System.Data.SqlServerCe.4.0';,entity-framework,c#-4.0,sql-server-ce,Entity Framework,C# 4.0,Sql Server Ce,在entityframework 6.0中使用sqlce 4.0时,出现以下错误 No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' 我的app.config看起来像这样 .... <configSections> <section name="log4net" type="log4net.Config

在entityframework 6.0中使用sqlce 4.0时,出现以下错误

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'
我的app.config看起来像这样

....
<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" >
      <parameters>
        <parameter value =" System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <!--providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers-->
  </entityFramework>
  <connectionStrings>
    <add name="FbMultipleInsOrderContainer" connectionString="metadata=res://*/FbMultipleInsOrder.csdl|res://*/FbMultipleInsOrder.ssdl|res://*/FbMultipleInsOrder.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=|DataDirectory|\FBMultipleOrderSync.sdf&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
...
。。。。
...
我试着重新安装EF6。但是没有用

关于这一点的任何线索都是值得注意的

安装nuget软件包后,检查app.config是否包含以下内容(根据上面@ErikEJ的评论):



(即使您并不真正需要SqlClient,您也可以保留该行。)

ErikEJ已经指出了这一点,但我想强调一个事实,您必须记住安装Nuget软件包

EntityFramework.SqlServerCompact

我尝试按照建议的答案进行操作,但没有意识到我没有App.config引用的所需NuGet包。

要实现这一点,只需在package Manager控制台中注册
EntityFramework.SqlServerCompact

要执行此操作,请打开power manager控制台并键入以下命令:

PM> Install-Package EntityFramework.SqlServerCompact

不要忘记,PackageManager控制台从选定的启动项目中获取app.config/web.config

我在单元测试中遇到了这个问题。棘手的是错误并不是经常出现。 我通过在单元测试解决方案中添加以下类来解决此问题:

public static class Trick
{
    public static void FixEfProviderServicesProblem()
    {
        // this commented line should be used for SQL Server provider
        //var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

        // this is used for SQL Server CE provider
        var instance = System.Data.Entity.SqlServerCompact.SqlCeProviderServices.Instance;
    }
}

我的问题是单元测试。您可能只安装了项目的实体框架,而没有安装单元测试。为此:

右键单击解决方案资源管理器中的“解决方案”(而不是项目名称)

单击“管理NuGet软件包”

搜索EntityFramework并按它


您可能不会在[Project Name]旁边看到勾号。测试此错误是在用户PC上出现的。用户忽略了以前的错误“每个配置文件只能显示一次“DBProviderFactorys”部分”

显然,DB2在她的PC上添加了一个重复(且为空)的
标记,从而损坏了机器配置文件


解决方案是删除空的重复标记。要解决此问题,机器配置文件位于[WindowsDir]\Microsoft.Net\Framework[.Net版本]\config\machine.config

Visual Studio菜单->工具->NuGet软件包管理器->管理解决方案的NuGet软件包

选择“浏览”选项卡并搜索以下“EntityFramework.SqlServerCompact”

安装它


它应该可以工作。

提供的解决方案是正确的,但它没有解释EF需要此组件的原因。这就是为什么

默认情况下,EF的配置允许您拥有“defaultConnectionFactory”uder entityFramework部分。此默认工厂配置为“LocalDbConnectionFactory”,其参数为“MSSQLSLocalDB”

该工厂内部需要“SqlServerCe.4.0”,即“SqlServerCompact”

仅当EF在DbContext中使用其默认连接字符串时,才会发生此错误。如果在配置中为EF提供了其他指定的连接字符串,则不会出现此错误。因为默认情况下EF使用默认连接工厂

安装“SqlServerCe 4.0”后,EF的配置将更改,“LocalDbConnectionFactory”及其参数“MSSQLServerLocalDB”将替换为“SqlServerCe 4.0”。EF运行时还能够找到SqlServerCe4.0程序集(因为它现在是引用的一部分,并且实际放置在BIN中)

以下是安装Sql Server Compact前后的EF配置

旧配置:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>

新配置如下所示:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>

此外,它还添加了以下部分来描述新工厂

<system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>


对我来说,因为程序员不仅仅是一个,有些程序员已经安装了EntityFramework.SqlServerCompact,但当我拉入电脑并运行上面显示的错误消息时,我只需卸载并再次安装。

在Visual Studio中,存在于
\u bin\u deployableAssemblies
文件夹中的所有
.dll
文件都需要设置为
生成操作

我所有的.dll都设置为
content

这就是我设定的,它在以下情况下立即起作用:


我将下面的提供程序代码添加到
Web.config
中,并同时安装
EntityFramework.SqlServerCompact
包,然后解决问题

如果缺少一个,它就会失败



您安装了EntityFramework.SqlServerCompact软件包吗?您需要一个“现在我被击中”实体框架提供程序类型“System.Data.Entity.SqlServerCompact.SqlCeProviderServices”,无法加载EntityFramework.SqlServerCompact'在ADO.NET提供程序的应用程序配置文件中注册,该提供程序的固定名称为'System.Data.SqlServerCe.4.0'。问题已解决。我必须再次将这些包添加到我的消费者项目中。1。在Visual Studio解决方案资源管理器2中选择您的解决方案。转到工具->库包管理器->包管理器控制台3。Visual Studio的底部将出现一个窗口。4.键入此命令:安装包EntityFramework.SqlServerCompact 5。按下回车键。这将安装EntityFramework.SqlServerCompact Nuget软件包,该软件包将修复此问题。+1到此。。这真的应该添加到主要答案中!我将请求编辑,因为我没有使用实体框架,但正在使用一个可能早于实体框架的旧库,这就解决了我的问题。非常感谢。
<system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>