1

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

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.

Community
  • 1
  • 1
Steve
  • 355
  • 4
  • 15

3 Answers3

2

I got it sorted out, after attempting to restore an older version of the EF files from source control and still running into the same issue, I realized the reference was probably in a project file.

In [projectName].vbproj I found these two entries:

    <Compile Include="Data\schedulerModel.Context1.vb">
          <AutoGen>True</AutoGen>
          <DesignTime>True</DesignTime>
          <DependentUpon>schedulerModel.Context.tt</DependentUpon>
        </Compile>
    <Content Include="Data\schedulerModel.Context.tt">
          <Generator>TextTemplatingFileGenerator</Generator>
          <DependentUpon>schedulerModel.edmx</DependentUpon>
          <LastGenOutput>schedulerModel.Context1.vb</LastGenOutput>
        </Content>

I removed the first, and dropped the 1 from the context.vb file in the second, opened the project and ran a rebuild without issue.

Steve
  • 355
  • 4
  • 15
2

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>
David Spence
  • 7,999
  • 3
  • 39
  • 63
0

Just thought I'd add my findings to this as it has been driving me to distraction for a few weeks - every time I updated my Model from Database, I got "duplicate" context, designer files etc, and then hundreds of errors. However, the new sp or table or whatever I had added was only present in the new "context1" files, not the originals, so when I wound it back I had to go through the same process again etc etc.

Then finally a light went on when I thought of ... Source Control! I use TFS, and I found that unless ALL model-related files are checked out before doing the Update, so that's Context, Designer and Service files, then EF generates new versions of almost everything, presumably because it can't modify one of the files which are read-only due to source-control.

The key then is to fix the project file as stated in answers above before getting everything checked out and THEN doing the update. If you don't get that tag right in the proj file, it goes and does it all wrong again even though everything is checked out.

Hope this helps - my sanity is slowly returning anyway.

Ade

Ade
  • 96
  • 5