Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Update Model from Database" does not see a type change

I have several columns that I changed from Int to BigInt.

I opened up my EF model and did an 'Update Model from Database' and expected to see those columns now be Int64s. But they are still Int32s.

(I ran it several times just to be sure.)

I double checked my database and the columns are definitely BigInts.

So... does 'Update Model from Database' not work for a change of data type? Does it need to be manually applied?

like image 696
Vaccano Avatar asked Sep 15 '11 20:09

Vaccano


4 Answers

Unfortunately, you'll need to delete the items from your model and then add them back in - at least that's the only thing I have managed to get working.

There is at least one third-party tool that is supposed to help with this, but have not tried it personally.

like image 81
E.J. Brennan Avatar answered Oct 12 '22 11:10

E.J. Brennan


I'm using VS2008 SP1. If you change the datatype in the "ModelView" (CSDL) of the edmx, errors will occur because the "DatabaseModel" (SSDL) is not updated. You have to edit the *.edmx manually (XML). That is not so hard as it sounds.

You can simply search for the Property that the "Error List" of VS provides you (search in files is maybe the best solution for this). Go to the line where the wrong datatype appear and fix it.

e.g. you changed float to nvarchar(50) on the database --> go to your model and change Double to String --> validate --> Error.... --> Search for the property and make following changes:

      <Property Name="YourChangedProperty" Type="float" />

to

      <Property Name="YourChangedProperty" Type="nvarchar" MaxLength="50" />

This works very well if you know exactly what you've changed on the database. If you've made countless changes, you would have to analyse your changes with some DB-compare tool or regenerate the whole model.

Not very nice. But it "works".

take care M

like image 37
Mat Avatar answered Oct 12 '22 12:10

Mat


Correct - data types don't appear to update automatically. You can simply change the data type in the model view using the Properties window and change the Type to Int64.

like image 5
Michael Gattuso Avatar answered Oct 12 '22 12:10

Michael Gattuso


Answer

For the specific scenario you mentioned, you will need to manually change the Type from Int32 to Int64.

There are a number of ways that this can be done, but the easiest is probably just to open the model (using the default editor) and change the Type of the property from Int32 to Int64.

Explanation (from MSDN Library)

The ADO.NET Entity Data Model Designer (Entity Designer) uses the Update Model Wizard to update an .edmx file from changes made to the database. The Update Model Wizard overwrites the storage model as part of this process. The Update Model Wizard also makes some changes to the conceptual model and mappings, but it only makes these changes when objects are added to the database. For example, new entity types are added to the conceptual model when tables are added to the database, and new properties are added to entity types when columns are added to a table. For details about what changes are made to the .edmx file, see Changes Made to an .edmx File by the Update Model Wizard.

For your scenario, the important thing to note is that the update model wizard is updating the .edmx file with your changes, but only to the storage model. When changes are made to the definition of existing columns, the conceptual model is not updated. For a complete description of changes made by the update model wizard, please see the "Changes Made to an .edmx File by the Update Model Wizard" link above.

like image 4
timb Avatar answered Oct 12 '22 12:10

timb