C# 实体框架6(代码优先)添加迁移将错误的提供程序放入edmx架构

C# 实体框架6(代码优先)添加迁移将错误的提供程序放入edmx架构,c#,entity-framework-6,C#,Entity Framework 6,我有一个最初使用System.Data.SqlServerCe.4.0(MSSQL Compact Edition 4.0)数据提供程序的项目。然后我做了一个分支,更改了System.Data.SqlClient(MSSQL提供程序)的配置文件和引用,卸载了EntityFramework for MSSQLSCE nuget包。分支项目中的所有内容都正常工作,除了两件事:添加迁移和数据库种子脚本失败,出现下一个错误: Schema specified is not valid. Errors:

我有一个最初使用System.Data.SqlServerCe.4.0(MSSQL Compact Edition 4.0)数据提供程序的项目。然后我做了一个分支,更改了System.Data.SqlClient(MSSQL提供程序)的配置文件和引用,卸载了EntityFramework for MSSQLSCE nuget包。分支项目中的所有内容都正常工作,除了两件事:添加迁移和数据库种子脚本失败,出现下一个错误:

Schema specified is not valid. Errors: (0,0) : error 0175: The ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' is either not registered in the machine or application config file, or could not be loaded
我试图找到问题的根源,最后发现存储在MSSQL项目数据库的_MigrationHistory中的EDMX模式包含下一行:

<Schema Namespace="CodeFirstDatabaseSchema" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" Alias="Self" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">

但我不明白,为什么它是用Provider=“System.Data.SqlServerCe.4.0”选项生成的?我检查了我的分支项目是否没有任何文件,其中包含SqlServerCe子字符串(在操作系统中进行了文件搜索)。我已尝试重新安装EntityFramework NuGet软件包,但也没有帮助

App.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="AppDBContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=AnalyticDB;Persist Security Info=True;Trusted_Connection=Yes;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

EF版本:6.1.2


谢谢

在删除SQL CE引用之前,是否对数据库运行迁移。您将不得不取消_MigrationHistory表。谢谢您的回答,Erik,不幸的是,这没有帮助。在删除指向CE的链接(将数据库还原为0迁移,然后再次更新)后,我多次这样做,但仍然存在错误的提供程序。是否有任何方法可以跟踪构建EDMX架构的过程?是否尝试删除迁移?如果可能,请随时共享一个复制项目(通过我的博客向我发送电子邮件)。最终我找到了解决方案:EF迁移在其资源文件中包含连接引用的db模型,因此如果您为一台db服务器创建迁移(在我的情况下是MsSql CE),不能将它们应用于其他数据库。我为我的分支项目重新创建了它们,现在一切都好了。首先,代码有相同的问题:在一个项目中,我使用Sqlite,在第二个项目中使用SQLCE。我从Sqlite开始。当我尝试在SQLCE上应用迁移时,它显示“System.Data.SQLite.EF6”丢失了——这很奇怪,因为该项目不包含任何对SQLite的引用。