Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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提供程序SqlServerCe.3.5而不是4.0_Entity Framework_Sql Server Ce_Microsoft Sync Framework_Sql Server Ce 4_Sql Server Ce 3.5 - Fatal编程技术网

Entity framework 实体框架查找ADO.NET提供程序SqlServerCe.3.5而不是4.0

Entity framework 实体框架查找ADO.NET提供程序SqlServerCe.3.5而不是4.0,entity-framework,sql-server-ce,microsoft-sync-framework,sql-server-ce-4,sql-server-ce-3.5,Entity Framework,Sql Server Ce,Microsoft Sync Framework,Sql Server Ce 4,Sql Server Ce 3.5,我正在使用SQLServerCE4.0和EntityFramework6.0。在我想使用WCF服务和同步框架2.1启用与远程数据库的N层同步机制之前,一切都很正常 我遵循了这一点,并使用解决了SyncFramework 2.1和SQLSErverCompactCE 4.0兼容性不受支持的问题。这只是System.Data.SqlServerCE.dll 4.0.0的app.config中的运行时绑定重定向 然后我得到以下App.config文件 <?xml version="1.0" en

我正在使用SQLServerCE4.0和EntityFramework6.0。在我想使用WCF服务和同步框架2.1启用与远程数据库的N层同步机制之前,一切都很正常

我遵循了这一点,并使用解决了SyncFramework 2.1和SQLSErverCompactCE 4.0兼容性不受支持的问题。这只是System.Data.SqlServerCE.dll 4.0.0的app.config中的运行时绑定重定向

然后我得到以下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>
  <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>
  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/Persistence.Model1.csdl|res://*/Persistence.Model1.ssdl|res://*/Persistence.Model1.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=|DataDirectory|\XXXX.sdf&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<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>
</configuration>
请注意,中提供的解决方案不可行,因为在我的情况下,我确实需要绑定重定向来使用SyncFramework


有没有一种方法可以告诉entity framework不要查找SQL Server CE 3.5提供程序,而只查找4.0?

我想我明白了。当SQL Server CE 3.5安装在计算机上时,它将被添加到machine.config中的DbProviders中,并且根据它在4.0版本中的位置,您可能会出现故障(请参阅上面的注释)。看起来app.config允许您删除DbProviderFactory。我在app.config中添加了以下行,问题似乎已经解决

<system.data>
  <DbProviderFactories>
    <remove invariant="System.Data.SqlServerCe.3.5" />
  </DbProviderFactories>
</system.data>


Try with:另请查看我的博客帖子,包括博客评论,您的最佳选择可能是要求卸载3.5版本..:-(非常感谢,解决了“找不到实体框架提供程序”的问题,但我们得到了“无效强制转换”的异常。你在junet的帖子中尝试了绑定重定向了吗?现在你的绑定重定向是什么?我保留了这一条很好的信息,我可以用它来改进我的EF私有部署nuget包!
<system.data>
  <DbProviderFactories>
    <remove invariant="System.Data.SqlServerCe.3.5" />
  </DbProviderFactories>
</system.data>