实体框架6从数据库更新忽略已删除的列,键入更改 [英] Entity Framework 6 Update from Database ignores deleted columns, type changes

查看:80
本文介绍了实体框架6从数据库更新忽略已删除的列,键入更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里缺少一些东西?



我有一个.net 4.5.1项目,其中包含从SQL 2005数据库创建的实体框架模型(连接类型为SQL服务器也),通过ADO.NET实体数据模型。



这工作正常。就是说,直到我更新数据库。如果我将新的表或列添加到现有的表中,那么一切都很好,但是如果我删除了一个列,那么更新不能正常工作。当我更改列类型时,它也会抛出错误。



同样的问题早已报告: http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#。 UytNrvldVD0 ,但这似乎太可笑了,我不敢相信我没有缺少某些东西。当然我做错了吗?如何让模型更正?

解决方案

我有同样的问题。我打开了Model,从图中删除了已更改的表,然后从Database更新并重新添加了表。
EF使用正确的结构重新启动桌面。保存模型,重建项目,所有内容都按预期方式显示。



我不知道为什么它不会检测到已删除的列。我相信如果您更改列的数据类型,但还没有测试它。但是上述解决方案迄今为止对我来说很有用。


Am I missing something here?

I've a .net 4.5.1 project with an Entity Framework model created from a SQL 2005 database (Connection type is SQL Server also), via "ADO.NET Entity Data Model".

This works fine. That is, until I update the database. If I add new tables or columns to existing tables all is well, but if I delete a column, the update just doesn't work properly. it also throws out errors when I alter the column type.

This same problem was reported a long time ago: http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#.UytNrvldVD0, but it seems so ridiculous I can't believe I am not missing something. Surely I'm doing something wrong? How can I get the model to update properly?

解决方案

I have the same problem. I opened up the Model, removed the changed tables from the diagram, then Updated from the Database and re-added the tables. EF brought the table back in again with the correct structure. Save The model, Rebuild the project, everything turns up as expected.

I am not sure why it doesn't detect the deleted columns. I believe there's also issues if you change the data type of the columns, but I've not tested it. But the above solution has worked for me so far.

这篇关于实体框架6从数据库更新忽略已删除的列,键入更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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