更新EF6 edmx模型会导致创建新的模型文件(Updating EF6 edmx model causes new model file to be created)

编程入门 行业动态 更新时间:2024-10-18 12:19:34
更新EF6 edmx模型会导致创建新的模型文件(Updating EF6 edmx model causes new model file to be created)

我正在使用EF 6.1和VS下载的T4模板。 当我尝试使用新信息更新EF模型,或者只是从我的数据库发出刷新时,模型文件会重复,并且会出现大量错误。

因此,例如,我的模型文件名为Test.edmx,其中包含名为Test.Designer.vb和TestModel.tt的子文件。 TestModel.tt有一个名为TestModel.vb的子文件,它似乎包含我所有的实体框架模型。

当我右键单击设计图面并选择“从数据库更新模型”,并添加新实体或刷新现有实体,而不是更新TestModel.vb文件时,它会创建一个名为TestModel1.vb的全新文件。 一旦发生这种情况,我会得到数千个重复的项目例外,因为现在有一个双打。

为什么会发生这种情况,我该如何解决? 配置错了吗? 此模型以前使用EF4,并使用这些说明直接升级到6。 https://msdn.microsoft.com/en-us/data/upgradeef6.aspx

I'm using EF 6.1 with the downloaded T4 template from VS. 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.

So, for example, my model file is called Test.edmx, which has subfiles called Test.Designer.vb and TestModel.tt. The TestModel.tt has a subfile called TestModel.vb which appears to contain all my entity framework models.

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. 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. https://msdn.microsoft.com/en-us/data/upgradeef6.aspx

最满意答案

听起来你的model / tt文件和输出文件之间的链接已被破坏。 您可以在文本编辑器中打开项目(vbproj)文件,然后查找test.edmx或testmodel.tt。 您应该在某个节点内找到其中一个或两个。 封闭节点中的文件是依赖于它们的文件。 猜测你会发现这是目前的TestModel1.vb。 您可以尝试编辑它并重新打开项目,但最简单的方法可能是排除现有的TestModel.vb并让visual studio使用它。 毕竟它应该是一个隐藏文件

It sounds like the linkage between your model/tt file and the output file has been broken. You could open the project (vbproj) file in a text editor and look for test.edmx or 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. 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. It should be a hidden file after all

更多推荐

本文发布于:2023-04-28 02:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   文件   edmx   created   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!