Database First Entity Framework Update Model is not working: What can be the reason?
Asked Answered
P

6

10

I have an existing MVC 3 application using entity framework 4. The model was generated using a Database-First Mode. I have also "automatic code generation" that generate the class.

Today, I did a simple modification to my database. A field went from "int" to "float". I went to the .edmx, did a right-click, Update model from database...

But when I look at the field, it didn't change at all. I double-check everything,and the database is modified, but the model never change... Does it mean I need to do this by hand?

I remember that I did a couple of update before (like 2 months ago) and it seems to work at the time... What can be broken that I need to check?

EDIT

When looking at the edmx diff file in subversion, the change seems to be done but when looking at it in "graphical mode", the change is not there. Also, no generated code is updated.

-          <Property Name="PreparationTime" Type="int" Nullable="false" />
+          <Property Name="PreparationTime" Type="float" Nullable="false" />
Polarization answered 29/5, 2013 at 0:52 Comment(1)
Does this answer your question? POCO Class in EF not working as ExpectedHaply
G
11

This is the normal behavior. ;-)

Your conceptual model will not change if you just modify something DB side, even if you perform the "Update model from database" wizard. Please have a look at this SO answer where I explain how an EDMX is built and how it should evolve.

Gagne answered 29/5, 2013 at 8:14 Comment(0)
B
3

Check List

  • Check Output window for any error occurred during command Update model from database
  • Check your database connection string from .edmx property window
  • Any custom code generation template that's causing it?
  • Backup a copy of your .edmx, then try removing the modified entity from .edmx and re-add it back
Buroker answered 29/5, 2013 at 1:2 Comment(1)
1) Output is ok! 2)The connection string never change and see my edit, the change seems to work in the file itself 3) I use the EF4 code generator as is 4) Will try that only if it's my last resort!Bursary
J
1

I know this is an old question, but since the given answer did not work in my case, I thought I'd just leave my solution here for others with a similar issue.

Assuming you are working with SQL Server Management Studio:

  • Right click "Database Diagrams" and select "New Database Diagram".
  • Include all the tables (except for "__MigrationHistory", if present) and press "Add".
  • Try to update your EDMX again.

For me, this was the solution, after months where I'd been using work-arounds for a project where the edmx was crucial, but refused to update in a normal way anymore. A new co-worker mentioned this as possible fix. The hours I could have saved if I had known this earlier...

Jeanettajeanette answered 15/8, 2016 at 13:34 Comment(0)
A
1

Try this hack from MSDN

1.Build the project after updating EDMX file.

2.Right click your .tt file in solution explorer.

3.Select "Run Custom Tool" option.

Asaph answered 27/4, 2019 at 11:35 Comment(2)
This messed up my context and now I get "unable to locate file" when I try to build.Trope
Model.Context.cs is empty now. Do NOT follow what this answer suggests.Trope
T
0

All answers above did not fix my problem. Here is what fixed the issue for me:

Check your warnings section, the table you want to update/add in your model does not have the necessary elements (primary key missing for example). Update your database table to fix the warnings then update your model.

Towline answered 27/7, 2020 at 13:15 Comment(0)
E
0

This problem solved in Visual Studio 2022 - Version 17.7.0

Einsteinium answered 15/8, 2023 at 13:40 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Recurrent

© 2022 - 2024 — McMap. All rights reserved.