简体   繁体   English

更新EF6 edmx模型会导致创建新的模型文件

[英]Updating EF6 edmx model causes new model file to be created

I'm using EF 6.1 with the downloaded T4 template from VS. 我正在将EF 6.1与VS下载的T4模板一起使用。 When I try to update the EF model with new information, or just issue a refresh from my database, the model file duplicates and I get a massive amount of errors. 当我尝试用新信息更新EF模型时,或者只是从数据库中发出刷新时,模型文件重复,并且出现了大量错误。

So, for example, my model file is called Test.edmx, which has subfiles called Test.Designer.vb and TestModel.tt. 因此,例如,我的模型文件称为Test.edmx,其中包含名为Test.Designer.vb和TestModel.tt的子文件。 The TestModel.tt has a subfile called TestModel.vb which appears to contain all my entity framework models. TestModel.tt有一个名为TestModel.vb的子文件,该文件似乎包含我所有的实体框架模型。

When I right click on the design surface and select "update model from database", and either add a new entity or refresh an existing one, instead of updating the TestModel.vb file, it creates a whole new file called TestModel1.vb. 当我右键单击设计图面并选择“从数据库更新模型”,然后添加一个新实体或刷新现有实体,而不是更新TestModel.vb文件时,它将创建一个名为TestModel1.vb的全新文件。 Once that happens I get thousands of duplicate item exceptions, because now there a doubles. 一旦发生这种情况,我就会得到成千上万个重复的项目异常,因为现在有两倍的异常。

Why is this happening, and how can I fix it? 为什么会发生这种情况,我该如何解决? Is something configured wrong? 配置错误吗? This model was previously using EF4 and was upgraded straight to 6 using these instructions. 该模型以前使用EF4,并已按照这些说明直接升级为6。 https://msdn.microsoft.com/en-us/data/upgradeef6.aspx https://msdn.microsoft.com/zh-CN/data/upgradeef6.aspx

It sounds like the linkage between your model/tt file and the output file has been broken. 听起来您的model / tt文件与输出文件之间的链接已断开。 You could open the project (vbproj) file in a text editor and look for test.edmx or testmodel.tt. 您可以在文本编辑器中打开项目(vbproj)文件,然后查找test.edmx或testmodel.tt。 You should find one or both of them inside nodes somewhere. 您应该在某个位置的节点内找到它们之一或两者。 The file in the enclosing node is the one that depends upon them. 封闭节点中的文件就是依赖于它们的文件。 At a guess you'll find this is currently TestModel1.vb. 大概您会发现它当前是TestModel1.vb。 You could try editing this and reopening the project, but the simplest thing might be to exclude your existing TestModel.vb and let visual studio have its way. 您可以尝试对此进行编辑并重新打开项目,但是最简单的方法可能是排除现有的TestModel.vb,然后让Visual Studio自行处理。 It should be a hidden file after all 毕竟应该是一个隐藏文件

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

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