从实体框架中删除重复的Context.vb文件 [英] Remove a duplicate Context.vb files from Entity Framework

查看:41
本文介绍了从实体框架中删除重复的Context.vb文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS2013中的EF6有点问题.我必须为Web应用程序项目中的数据库优先模型修改连接字符串,因此我遵循了我该如何编辑的最佳答案中的建议实体框架连接字符串?,并将其从我的Web.Config文件中删除.最初,它似乎工作正常,我删除了连接字符串,然后从实体设计器中运行了从数据库更新模型",重新创建了连接字符串,但是随后我的构建失败,出现了多个错误,类似于:

I'm having a bit of an issue with EF6 in VS2013. I had to modify the connection string for the database-first model in a Web Application project so I followed the advice in the best answer for How should I edit an Entity Framework connection string? and deleted it from my Web.Config file. At first it seemed to work fine, I deleted the connection string then from the Entity Designer I ran "Update Model from Database", re-created the connection string, but then my build failed with multiple errors similar to:

Public Sub New() has multiple definitions with identical signatures

经过一些挖掘,我发现当我重新创建连接字符串EF时,创建了另一个名为Model.Context1.vb的Model.Context.vb文件,并且两者都仍在某处被引用.从那以后,我用记事本打开了包含我的EF模型的文件夹中的每个文件,以查找对Context.vb或Context1.vb的引用,并且空着,如果我删除了这两个文件,我的构建都会失败,说明找不到该文件,因此,作为一种解决方法,我打开了Context.vb文件并删除了所有代码,所以没有重复的代码,如果有人知道我能做些什么,我想通过删除对该文件的引用来删除它以正确地解决该问题.

After some digging I figured out that when I re-created the connection string EF created a second Model.Context.vb file named Model.Context1.vb and both are still referenced somewhere. Since then I've opened every file in the folder containing my EF model with notepad searching for a reference to Context.vb or Context1.vb and have come up empty, if I remove either file my build fails stating the file can not be found, so as a workaround I opened the Context.vb file and removed all the code so there are no duplicates, I'd like to fix it properly by removing the reference to the file deleting it if anyone knows how I can go about doing that.

推荐答案

我遇到了同样的问题,但解决方案略有不同.出于某种原因,一次更新edmx文件似乎从项目文件中删除了一条看似重要的行,该行读取< LastGenOutput> MyEntityModel.Context.cs</LastGenOutput> .

I had the same problem but a slightly different resolution. For whatever reason, updating the edmx file one time seemed to remove a seemingly important line from the project file, the line reading <LastGenOutput>MyEntityModel.Context.cs</LastGenOutput>.

我将该行重新添加到我的项目文件中,并且更新模型不会导致上下文文件重复.修复后,整个块如下所示:

I re-added the line to my project file and updating the model didn't result in any more duplicate context files. The whole block looked like the following when fixed:

<Content Include="MyEntityModel.Context.tt">
    <Generator>TextTemplatingFileGenerator</Generator>
    <DependentUpon>MyEntityModel.edmx</DependentUpon
    <LastGenOutput>MyEntityModel.Context.cs</LastGenOutput>
</Content>

这篇关于从实体框架中删除重复的Context.vb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆