为什么设计器在从数据库更新模型时要创建两个 .Designer.cs 文件?
就像问题所说:在 Visual Studio 中,在 Model.edmx 中,当我添加一些新的数据库字段后 从数据库更新模型... 时,它会创建一个几乎重复的 Model1.Designer.cs导致与原始 Model.Designer.cs 冲突的文件。
我可以删除新的 Model1.Designer.cs 文件,但新添加的字段不可用。
有没有解决方案(除了删除并重新创建模型)?
Like the question says: In Visual Studio, when in the Model.edmx, when I Update Model from Database... after adding a few new database fields, it's creating an almost duplicate Model1.Designer.cs file that is causing conflicts with the original Model.Designer.cs.
I can delete the new Model1.Designer.cs file, but then the newly added fields aren't available.
Is there a solution to this (other than deleting and recreating the model)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
听起来您可能已经删除并重新创建了模型(或类似的东西),但将原始设计器文件留在了目录中。然后,当您添加新模型时,它必须使用 Model1 而不是 Model 作为设计器文件名。您是否尝试过排除 Model.Designer.cs 文件并使其与 Model1.Designer.cs 文件一起使用?
好的,查看我们的一个包含模型的项目的项目文件,我可以看到以下可能相关的部分:
我相信这个部分告诉项目代码文件是项目的一部分,并且应该是文件 model.edmx,并在更改时重新生成。
我们还有此部分:
不确定其中哪个控制生成的文件名,但您可以尝试手动编辑项目文件以查看是否有所不同。我想说你需要同时改变两者,而不是只改变一个。
It sounds like you might have deleted and recreated the model (or something similar) but left the original designer file in the directory. Then when you added a new model it had to use Model1 instead of Model as the designer file name. Have you tried excluding the Model.Designer.cs file and leaving it working with the Model1.Designer.cs file instead?
Okay, looking at the project file for a project of ours with a model in, I can see the following potentially relevant sections:
I believe this one tells the project that the code file is part of the project, and should be a subnode of the file model.edmx, and be regenerated when it changes.
We also have this section:
Not sure which of these controls the generated file name, but you could try hand editing your project file to see if it makes a difference. I'd say you'd need to change both at the same time, rather than just one.
原因:
我可以重新创建此问题(并且偶尔会犯错误):在运行项目时尝试保存数据库图表(edmx 文件),导致 Visual Studio 无法写入各种文件,并且生成具有新名称的文件。可能还有其他方法可以通过使文件不可写入来重新创建它。该项目将继续工作,它只会给版本控制带来问题,我想象一些部署模型。
症状:
项目文件引用了冗余文件,例如:
补救措施
Cause:
I can recreate this (and do by mistake now and then): it occurs trying to save the database diagram (edmx file) while running a project such that Visual Studio cannot write to the various files and generates ones with new names. There may be other ways to recreate it by making the files unavailable for writing. The project will keep working, it just creates a problem for version control and I imagine some deployment models.
Symptoms:
extra enitity files in form of [entityname]1.vb, [entityname]1.cs such as Person1.vb
project file has references to redundant files such as:
Remedy
今天发生在我身上,我通过以下方法解决了这个问题:
This happened to me today, and I solved it by:
我遇到了同样的问题,模型正在生成第二个 Designer.cs 文件。这是在我安装 vs2010 时解决了与设计器相关的一大堆问题之后的结果(不知何故,vs2010 丢失了对与数据实体模型设计器相关的一堆 DLL 的引用,需要重新编辑和重新安装)。
根据凯文的建议,我手动编辑了项目文件以指向我喜欢的文件,并且它起作用了。设计者停止重新创建第二个文件。
I had the same problem, the model was generating a second designer.cs file. This was after working through a whole bunch of issues with my installation of vs2010 related to the designer (somehow vs2010 lost the references to a bunch of DLL's related to the Data Entity Model designer requiring rededits and reinstalls).
Taking Kevin's advice, I edited the project file manually to point to my preferred file and it worked. The designer stopped recreating the second file.
如果您使用任何版本控制实用程序(例如 SVN),最简单的修复方法是将工作副本与以前的修订版本进行比较,并恢复 .csproj 中设计者名称更改为带有“1”后缀的一行。
If you are using any version control utils like SVN, the easiest way to fix it is to compare working copy with previous revisions and revert one line in .csproj where designer name changed to that with '1' suffix.
此问题已报告给微软,但他们尚未能够重现。
请参阅https://connect.microsoft.com/VisualStudio/feedback/details/532800/msdatasetgenerator-create-another-designer1-cs-file-for-my-typed-dataset
This has been reported to Microsoft, but they haven't been able to reproduce it.
See https://connect.microsoft.com/VisualStudio/feedback/details/532800/msdatasetgenerator-create-another-designer1-cs-file-for-my-typed-dataset
遇到了同样的问题,并且旧的答案都不适合我。额外的设计师不断重新出现。
我的原因(在 .csproj 中):
解决方案:
额外的 SubType 导致 MSDataSetGenerator 每次运行两次。删除子类型后,您仍然需要删除任何其他错误生成的 MyDataSet1.Designer.cs 条目。请参阅 Kevin 的帖子了解几个示例。
Had the same issue, and none of the older answers worked for me. The extra designer kept re-appearing.
My Cause (in the .csproj):
Solution:
The extra SubType caused MSDataSetGenerator to run twice each time. After removing the subtype, you will still need to delete any other erroneously generated MyDataSet1.Designer.cs entries. See Kevin's post for a couple of examples.