Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework error on updating model from database and vice versa

Here is what happens when I try to update model from database with VS express 2013 for the web, EF6.1.1 and .NET framework 4.5.

In this case I just added a field to a table in the table definition and updated the database.

After that I right click update model from database in the EDMX model view and I get this error message:

An exception of type ‘System.runtime.interopServices.COMException’ occurred while attempting to update from the database. The exception message is: ‘A file or folder with the name ‘Model.Context.tt’ already exists. Please give a unique name to the item you are adding or delete the existing item first.

I noticed that I get the same error message when I try to generate the database from the model.

I tried the following methods:

  • How do you update an edmx file with database changes?
  • http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#.VMYYRv7A7mH

but none of them worked.

I also found that https://entityframework.codeplex.com/workitem/1104 and it seems that it has been resolved with “commit 7e8331d1d22d (EFTools repo)”.

Anyone can help me on how to solve my problem or on what is “commit 7e8331d1d22d (EFTools repo)” ?

Thanks

Boid’

like image 769
Boidot Avatar asked Jan 26 '15 15:01

Boidot


People also ask

How do I update items in Entity Framework?

This can be achieved in several ways: setting the EntityState for the entity explicitly; using the DbContext. Update method (which is new in EF Core); using the DbContext. Attach method and then "walking the object graph" to set the state of individual properties within the graph explicitly.


1 Answers

It's an old question but I just run into the same issue. Finally found a solution in this bug report. Check if you have any *.tt files that are not added to solution and remove them. That fixed the problem for me.

like image 194
Fuzzy Avatar answered Sep 27 '22 23:09

Fuzzy