且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

数据库迁移后更新实体框架EDMX模型

更新时间:2023-02-13 12:48:53

p>我们最终找到解决方案是通过转到SSMS中的属性>选项,将传统基数估算更改为 ON 。这允许我们将兼容性级别设置为数据库上的SQL Server 2016。



另请注意,通过Visual Studio中的更新向导更新这些模型时,模型似乎永远需要更新;我们结束了让精灵运行过夜,我们的一个数据库的模型终于在6个小时之后完成了更新。所以他们将最终完成更新,但不能在一个现实的时间框架内让某人使用。



在进行配置更改后,模型会立即更新,期望。



可以在Entity Framework的GitHub页面上找到提示我们进行此更改的问题 here 。看来,实体框架的贡献者在他们的最后没有发现错误,并将其交给SQL Server团队,但是根据我的了解,没有修复已经被实施了。


I have an issue where I have generated multiple EDMXs and models using the Entity Framework Database First approach, and these models were mapped to tables/stored procedures on a remote SQL Server 2012 instance initially. Now that we have migrated to SQL Server 2016, whenever we try to update these EDMX models by adding new tables, refreshing models, etc., the Update Wizard freezes indefinitely.

I have done some research in regards to this issue, and I've seen where some people have had luck changing the Compatibility Level on the databases in question, but that is something we would like to avoid if at all possible. After migrating, the Compatibility Level was set to SQL Server 2016 (130) for all databases on the server, specifically for query optimization purposes per our Microsoft database consultant.

Something I have tried changing manually is the ProviderManifestToken in the EDMX's XML content by setting it from "2012" to "2016", but this seems to cause other issues. I get this error message after doing so:

Error Message

Other possibly useful information:

  • Using Visual Studio 2015
  • Entity Framework version 6.1.3

Has anyone had any luck migrating from SQL Server 2012 to 2016 for their database while keeping clean mapping to auto-generated Entity Framework models? It seems there would be a built in tool to clean up the EDMXs to map cleanly to a new and updated instance of SQL Server.

What we ended up finding as a solution is to change Legacy Cardinality Estimation to ON for the database in question by going to Properties > Options in SSMS. This allowed us to keep the compatibility level set to SQL Server 2016 on the database.

As an additional note, when updating these models through the Update Wizard in Visual Studio, the models would seemingly take forever to update; we ended up leaving the wizard running over night and the models for one of our databases finally finished updating after ~6 hours. So they will eventually finish updating, but not in a realistic time frame for someone to work with.

After making the configuration change, the models would update instantly, as one would expect.

The issue that tipped us off to making this change can be found on Entity Framework's GitHub page here. It appears that the contributors to Entity Framework have not found fault on their end and have handed this over to the SQL Server team, but no fix has been implemented at the time of this posting (to my knowledge).