4

new to Entity Framework....

I am currently using the latest update for EF and Visual Studio 2012, when trying to refresh from the database to update tables in my model that have changed, the designer is throwing a COMException "A file or folder with the name 'XXXXModel.Context.tt' already exists. Please give a unique name to the item our are adding.

It looks like it wants me to delete all my model files when refreshing from DB, this can't be right. Am I missing something?

Gary
  • 185
  • 2
  • 10
  • I'm confused. Are you trying to update database or update your models? – Sefa Jan 29 '15 at 14:48
  • the error occurs when refreshing the model after tweaks to the database. – Gary Jan 29 '15 at 15:02
  • Here, another related question, still no answers: http://stackoverflow.com/questions/28153536/entity-framework-error-on-updating-model-from-database-and-vice-versa – NahuelGQ Mar 12 '15 at 15:08
  • I don't know what happened, but in my case, I undid all my changes and forced an overwrite from source control. I think that fixed this error, but then it started asking for a connection string as if it were a new DbContext. It turned out the user in my connection string wasn't associated with the Login in SQL server so it was unable to connect with the existing connection string. So the user problem may have contributed to the original error, but I'm not sure. – xr280xr Jul 30 '19 at 14:24

2 Answers2

5

This happens because entity framework creates your model in an auto generated container.designer.cs file. This file contains classes that map with your database tables.

On this occasion, don't delete the model but only delete .tt files

Frank
  • 4,461
  • 13
  • 28
husonos
  • 241
  • 3
  • 14
1

It happened to me too. I blamed Db Context generator which did not override previous generated POCO classes.

How to get over it is to follow answer from @husonos, where:

  1. delete *.tt files upon your .edmx file in the project
  2. Add new "Code generation Item" (by right clicking on edmx design view)
  3. select Db Generator (<>.tt)
  4. name it, save it

and then you should be all good to go.

In some cases the message saying override existing might appear, I did go for yes.

st35ly
  • 1,215
  • 18
  • 24