简体   繁体   English

更新 Entity Framework model 后,Visual Studio 看不到变化

[英]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:目前可用的解决方法是:

  1. Install VS 2012 Update 1 which should fix the bug.安装 VS 2012 Update 1 应该可以修复这个错误。
  2. If you are not in a position to install Update 1, you will have to right click on the model.tt T4 template file and click run custom tool.如果您无法安装 Update 1,则必须右键单击 model.tt T4 模板文件,然后单击运行自定义工具。 This will update the classes for you.这将为您更新课程。

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这是为我做的

Right click the .tt file and select "Run Custom Tool", that should update it:右键单击.tt文件并选择“运行自定义工具”,应该会更新它: 看图片

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我做了什么来使这个工作

  • Update visual Studio 2012 Update 5 (Not Working)更新 Visual Studio 2012 Update 5(不工作)
  • Update/Modify from Programs (Not working)从程序更新/修改(不工作)
  • After update stored procedures, build the project again then go to context.cs, right click and run custom tool (Not Working)更新存储过程后,再次构建项目然后转到context.cs,右键单击并运行自定义工具(不工作)
  • Doing RND (Someone says the issue is due to some permissions in MSSQL) But unfournately I have done alot of permission in MSSQL but (Not Working)做 RND(有人说这个问题是由于 MSSQL 中的一些权限造成的)但是 unfournately 我已经在 MSSQL 中做了很多权限但是(不工作)
  • Install 2019 and run the project.安装2019并运行项目。 Now everything works fine现在一切正常

Conclusion结论

  • Visual studio 2012 have a bug (bug is resolved in Update 1, 2, 3 and 4) Visual Studio 2012 有一个错误(错误已在更新 1、2、3 和 4 中解决)
  • Change the Visual Studio version will resolve the issue更改 Visual Studio 版本将解决问题

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.

相关问题 Visual Studio中的实体框架,手动更改未保存在模型类中 - Entity framework in visual studio, manual changes not saved in model class 在 Visual Studio 2022 上添加实体框架 Model - Adding Entity Framework Model on Visual Studio 2022 模型更改后更新数据库 - 实体框架7 - Update Database after Model Changes - Entity Framework 7 实体框架未更新更改6 - Entity Framework not updating changes 6 更新实体框架模型 - Updating Entity Framework Model 为什么visual studio会在更新实体框架模型时删除我的类 - why does visual studio delete my classes when I update entity framework model 在Entity Framework Database First中更改代码后更新数据库 - Updating database after code changes in Entity framework Database First 将数据库移至新服务器后,无法在Visual Studio 2010的实体框架设计器中看到SQL Server 2008表 - Unable to see SQL Server 2008 tables within entity framework designer of visual studio 2010 after moving database to new server 从Visual Studio数据库项目生成实体框架模型 - Generate Entity Framework model from Visual Studio database project 更新数据库和更改模型后实体框架验证错误 - Entity framework validation error after updating database and changing model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM