[英]After updating Entity Framework model, Visual Studio does not see changes
If I do any changes to my EF 5.0 model, VS does not seem to see the changes.如果我对 EF 5.0 model 进行任何更改,VS 似乎看不到更改。 I have tried adding a new table, which shows up fine in the model, but then if I try to use it somewhere the table does not show up in intellisense and I can't use it.
我尝试添加一个新表,它在 model 中显示正常,但是如果我尝试在某个地方使用它,该表不会显示在智能感知中,我无法使用它。
I have also tried changing datatypes of a column, which again shows up fine if I look at the.edmx model file, but visual studio will still give me compiler errors on that field because I am trying to assign the incorrect datatype.我还尝试更改列的数据类型,如果我查看 .edmx model 文件,它再次显示正常,但 visual studio 仍然会在该字段上给我编译器错误,因为我试图分配不正确的数据类型。
If I delete the EDMX completely, and recreate it, then the changes work fine.如果我完全删除 EDMX,然后重新创建它,那么更改工作正常。 but it is tiresome to regenerate from database each time when I should be able to just "update model from database" and rebuild.
但是每次我应该能够“从数据库更新 model”并重建时,从数据库重新生成是很烦人的。
I have never had these problems with EF before.我以前从未遇到过 EF 的这些问题。 Does anyone know the cause or the fix to this problem?
有谁知道这个问题的原因或解决方法?
Thanks.谢谢。
First Build your Project and if it was successful, right click on the "model.tt" file and choose run custom tool .首先构建您的项目,如果成功,请右键单击“model.tt”文件并选择运行自定义工具。 It will fix it.
它会修复它。
Again Build your project and point to "model.context.tt" run custom tool.再次构建您的项目并指向“model.context.tt”运行自定义工具。 it will update DbSet lists.
它将更新DbSet列表。
如果这是位于文件夹中的 edmx 文件的错误,现在已修复 - 下载并安装 VS 2012 Update 1。您可以从以下位置获取: http : //www.microsoft.com/visualstudio/eng/downloads#d- visual-studio-2012-update
This is apparently a bug in the Entity Framework that the model does not get updated when your Edmx file is located inside a folder.这显然是实体框架中的一个错误,即当您的 Edmx 文件位于文件夹内时,模型不会更新。 The workarounds available at the moment are:
目前可用的解决方法是:
Hope that helps someone out there.希望能帮助那里的人。
Link: http://thedatafarm.com/blog/data-access/watch-out-for-vs2012-edmx-code-generation-special-case/链接: http : //thedatafarm.com/blog/data-access/watch-out-for-vs2012-edmx-code-generation-special-case/
I also had this problem, however, right-clicking on the model.tt file and running "Custom tool" didn't make any difference for me somehow, but a comment on the page Ghlouw linked to mentioned to use the menu item "BUILD > Transform All T4 Templates."我也遇到了这个问题,但是,右键单击 model.tt 文件并运行“自定义工具”对我没有任何影响,但是 Ghlouw 链接到的页面上的评论提到使用菜单项“构建> 转换所有 T4 模板。” which did it for me
这是为我做的
You should have a <XXX>Model.tt
file somewhere which is the T4 template that generates your model classes.您应该在某处有一个
<XXX>Model.tt
文件,它是生成模型类的 T4 模板。
If it is in a different project, it will not update when you save the edmx file.如果它在不同的项目中,则在保存 edmx 文件时它不会更新。
Anyway, try right-clicking on it in Solution Explorer and choosing Run Custom Tool
无论如何,尝试在解决方案资源管理器中右键单击它并选择
Run Custom Tool
I searched for this answer because I had a similar situation in VS2013.我搜索这个答案是因为我在 VS2013 中也有类似的情况。 In my case, I found that a simple "
Clean Solution
" cleared out all the old definitions.就我而言,我发现一个简单的“
Clean Solution
”清除了所有旧定义。
Are you working in an N-Tiered project?您是否在 N 层项目中工作? If so, try rebuilding your Data Layer (or wherever your EDMX file is stored) before using it.
如果是这样,请在使用之前尝试重建数据层(或存储 EDMX 文件的任何位置)。
I've also experienced this problem with none of the classes being generated under the model.tt file.我也遇到过这个问题,没有在 model.tt 文件下生成任何类。 In my case it was down to issues with how I had built the DB in SQL2012.
就我而言,这归结为我如何在 SQL2012 中构建数据库的问题。 I'd set a column in a table to nullable that was also a foreign key and although I think you should be able to do this it caused a problem in EF5.
我将表中的一列设置为可为空的,这也是一个外键,虽然我认为你应该能够做到这一点,但它在 EF5 中引起了问题。
As soon as this was cleared and the diagram updated from the database they reappeared.一旦清除并从数据库更新图表,它们就会重新出现。
EF5 VS2013 EF5 VS2013
After Changing the laptop When I updating Entity Framework model, stored procedures are not seen in code更换笔记本电脑后当我更新实体框架模型时,代码中看不到存储过程
What I have done to make this working我做了什么来使这个工作
Conclusion结论
I had this problem in EF 6 using Visual Studio 2022. I tried all of the things here plus cleaning and rebuilding the solution, deleting the stored procedure out of EDMX and the database and re-updating, closing VS, and restarting my computer.我在使用 Visual Studio 2022 的 EF 6 中遇到了这个问题。我尝试了这里的所有操作以及清理和重建解决方案、从 EDMX 和数据库中删除存储过程并重新更新、关闭 VS 并重新启动我的计算机。 None of those things worked.
这些东西都不起作用。 What ended up fixing it was simply opening the DTSEF.vb file.
最终修复它的只是打开 DTSEF.vb 文件。 When I did that, Visual studio found the missing properties in the result object.
当我这样做时,Visual Studio 在结果 object 中找到了缺失的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.