Skip to content Skip to sidebar Skip to footer

Updating Entity Framework Model

I have just started using EF and found it cool, but I ran into a problem, Problem: I changed my DB schema of a column inside the table User, It was Varbinary(50) previously I then

Solution 1:

I've run into similar issues before, and found that the way to solve it was to delete the table from the model. Save and close the model. Then reopen the model and re-add the table.

Solution 2:

Shawn de Wet's solution works fine but In case you dont want to remove the table (for example relationship to some other tables..) you can use another solution: Open your edmx file with xml Editor, Ctrl + F to find a line similar to

Property Name="Email" Type="Binary" Nullable="false" MaxLength="50" FixedLength="false"

Update it to:

Property Name="Email" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false"

Save it and rebuild.

Solution 3:

A lot of files in the EF model get f*****d. Removing and adding the entity was not enough. The entities was duplicated like table, table1, table_result, table1_result, table_result1, and so on... Model update was updating the duplicated references instead of the original.

I have to open notepad and fix manually these files:

EFModel.Context.cs
EFModel.edxm

And delete these files:

obj\Debug\edmxResourcesToEmbed\MYEfModel.csdl
obj\Debug\edmxResourcesToEmbed\MYEfModel.msl
obj\Debug\edmxResourcesToEmbed\MYEfModel.ssdl

Solution 4:

No need to worry about it. Select the affected table in the model. If you observe, there you will find a new column name post fix with an integer (This behavior is only because of the change in the datatype of that column).

Example if your column name is "Samplecolumn", after updating the model from the database you will get a new column with Samplecolumn1. You can now simply remove the old column "Samplecolumn" and rename the new column "Samplecolumn1" to "Samplecolumn" using the properties window under general category.

Just build your app. The error will be gone.

Solution 5:

go to MyModel.edmx xml file, change Binary to String solved my issue

Post a Comment for "Updating Entity Framework Model"