
[英]Entity Framework code-first: migration fails with update-database, forces unneccessary(?) add-migration
[英]Entity Framework 6 (code first) Add-Migration puts wrong provider to the edmx schema
我有一个最初用于System.Data.SqlServerCe.4.0(MSSQL Compact Edition 4.0)数据提供程序的项目。 然后,我做了一个分支,更改了System.Data.SqlClient(MSSQL提供程序)的配置文件和引用,并为MSSQLCE nuget软件包卸载了EntityFramework。 分支项目中的所有内容都可以正常运行,只有两件事:添加迁移和数据库种子脚本失败,并出现下一个错误:
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子字符串(在OS中进行文件搜索)。 我试图重新安装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
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.