简体   繁体   English

实体框架6从数据库更新忽略已删除的列,键入更改

[英]Entity Framework 6 Update from Database ignores deleted columns, type changes

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". 我有一个.net 4.5.1项目,其中包含一个从SQL 2005数据库创建的实体框架模型(连接类型也是SQL Server),通过“ADO.NET实体数据模型”。

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. 很久以前就报道了同样的问题: http//blog.jongallant.com/2012/08/entity-framework-manual-update.html#.UytNrvldVD0 ,但它似乎太荒谬我不敢相信我不是遗漏了什么。 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. EF以正确的结构再次将桌子带回来。 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. 但到目前为止,上述解决方案对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM