DayTimeCoder
DayTimeCoder

Reputation: 4332

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 changed it into VarChar(50), and then inside the MyModel.edmx designer I chose "Update model from database", after clicking finish I received this error.

Error:

   Error 2019: Member Mapping specified is not valid.
    The type 'Edm.Binary [Nullable=False,DefaultValue=,MaxLength=100,FixedLength=False]' of member
   'Email' in type 'LearnDBModel.User' is not compatible with SqlServer.varchar 
    [Nullable=False,DefaultValue=, MaxLength=50,Unicode=False,FixedLength=False]' of member 'Email'
    in type 'LearnDBModel.Store.User'.

Let me know how to fix it

Upvotes: 24

Views: 29368

Answers (6)

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

Upvotes: 0

Tomas Kubes
Tomas Kubes

Reputation: 25178

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

Upvotes: 4

onvr
onvr

Reputation: 1

right click properties from changed table on Model.edmx[Diagram] and "Update model from database" . save and run

Upvotes: -2

Chinh Phan
Chinh Phan

Reputation: 1509

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.

Upvotes: 15

MSRS
MSRS

Reputation: 813

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.

Upvotes: 1

Shawn de Wet
Shawn de Wet

Reputation: 5996

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.

Upvotes: 61

Related Questions