24

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

2
  • 1
    Did you have any data in database? Commented May 19, 2012 at 17:37
  • @Xharze Actually the table in which I made changes is empty. Commented May 19, 2012 at 17:58

6 Answers 6

61

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.

Sign up to request clarification or add additional context in comments.

6 Comments

you also can cut/save/paste/save
if this did not work. you need to manually edit the .emdx file
This is f**ked. I thought EF was an industry standard. Another step that you might have to do is build the project before re-adding.
I am doing this that way since I came across this error and thought there had to be a better way. Seems like it doesn't :D
I was using asp mvc database first method, what i did was, deleted the whole model, and re-created again, works fine, hope helps someone.
|
15

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.

Comments

4

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

Comments

1

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.

Comments

0

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

Comments

-2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.