数据库迁移后更新实体框架EDMX模型 [英] Updating Entity Framework EDMX Models After Database Migration

查看:151
本文介绍了数据库迁移后更新实体框架EDMX模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我已经使用实体框架数据库第一种方法生成了多个EDMX和模型,这些模型最初映射到远程SQL Server 2012实例上的表/存储过程。现在我们已经迁移到SQL Server 2016,每当我们尝试通过添加新表,刷新模型等更新这些EDMX模型时,更新向导将无限期地冻结。



我已经对这个问题进行了一些研究,我看到有些人在运行的数据库中改变了兼容性级别,但是这是可以避免的。迁移后,服务器上的所有数据库的兼容性级别设置为 SQL Server 2016(130),具体用于根据我们的Microsoft数据库顾问进行查询优化。



我尝试手动更改的东西是EDMX的XML内容中的 ProviderManifestToken ,将其从2012设置为2016,但这似乎也会导致其他问题。这样做后我收到这个错误信息:



错误消息



其他可能有用的信息:




  • 使用Visual Studio 2015

  • 实体框架版本6.1.3



有人有任何运气迁移从SQL Server 2012到2016的数据库,同时保持干净的映射到自动生成的实体框架模型?似乎有一个内置的工具来清理EDMX,以便将其清晰地映射到新的和更新的SQL Server实例。

解决方案

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).

这篇关于数据库迁移后更新实体框架EDMX模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆