实体框架6.1删除列 [英] Entity Framework 6.1 delete a column

查看:77
本文介绍了实体框架6.1删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架(当前版本6.1.1)的数据库优先和Sql Express 2008作为存储。我有一个非常简单的模型,由两个表Foo和FooElements组成,具有一对多关系。我已经从表Foo中删除了列Bla,打开了我的.edmx文件,右键单击了一个空白处,并选择了从数据库更新模型,但删除的字段仍然在模型中。



当我尝试从DB获取Foo实体时,抛出异常:无效的列名称Bla。所以我从模型中删除了整个Foo实体,再次从DB中添加它,现在我还有一个异常 - 属性Bla不存在。



我尝试重新启动Visual Studio ,删除obj和bin文件,完全从项目中删除数据模型并从头创建它 - 它需要模型中的属性Bla,但是当我手动创建它时失败(列Bla不是自动创建的,因此列不存在DB)。



使我的项目再次运行的唯一解决方案是在DB中再次创建列Bla,并将其留在那里,尽管事实上我不需要它。



有没有办法从数据库中删除列,以便实体框架可以工作?
有什么类型的缓存文件,我必须清理?
谢谢。



甚至认为该领域不存在于edmx文件中,Entity框架仍然认为它是必需的。在哪里可以得到一个想法,DB中还有一些字段?

解决方案

谢谢大家的想法。 / p>

这个问题比我预想的更为微不足道。我的沙箱解决方案中的另一个项目是实体框架引用了DB中的同一个表,并且具有相同的模型名称,并且由于我完全忘记了它,所以我没有更新它,第二个项目中的.edmx文件包含旧的删除的字段。我从来没有想到两个不同的程序集可能会这样干扰,但是他们这样做。



解决方案是删除(或重命名)第二个项目中的模型,它现在正在工作。


I am working on an application with Entity Framework (current version 6.1.1) Database-first and Sql Express 2008 as a storage. I have a very simple model that consists of two tables Foo and FooElements with one-to-many relations.

I have deleted column Bla from table Foo, opened my .edmx file, right-clicked an empty space and selected "Update model from the database", but the deleted field remained in the model.

When I try getting the Foo entities from the DB, an exception is thrown: Invalid column name Bla. So I deleted the whole Foo entity from the model, added it from the DB again, now I have another exception - property Bla does not exist.

I tried restarting Visual Studio, removing obj and bin files, removing the data model from the project completely and creating it from scratch - it requires property Bla in the model, but fails when I create it manually (column Bla is not created automatically hence the column does not exist in the DB).

The only solution to make my project running again is to create column Bla in the DB again and leave it there, despite the fact that I don't need it.

Is there any way to delete a column from a DB so that the Entity framework can work afterwards? Is there any kind of cache file that I have to clean up? Thank you.

P.S. Even thought the field does not exist in the edmx file, Entity framework still thinks it is required. Where can it get an idea, that there are still certain fields in the DB?

解决方案

Thank you all for your ideas.

The problem was even more trivial than I expected. Another project in my sandbox solution had Entity Framework referencing the same table in the DB and it had the same model name, and since I completely forgot about it, I did not update it, and the .edmx file in the second project contained the old deleted fields. It never came to my mind that two different assemblies could interfere like that, but they did.

The solution is to remove (or rename) the model in the second project and it is working now.

这篇关于实体框架6.1删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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