Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Entity Framework Model

Tags:

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

like image 453
Owais Qureshi Avatar asked May 19 '12 17:05

Owais Qureshi


People also ask

How do I update my Entity Framework model in .NET core?

Right-click anywhere on the design surface, and select Update Model from Database... In the Update Wizard, select the Refresh tab and select your table then click Finish button.

How do I update Entity Framework model from database first?

Right-click anywhere on the design surface, and select Update Model from Database. In the Update Wizard, select the Refresh tab and then select Tables > dbo > Student. Click Finish. After the update process is finished, the database diagram includes the new MiddleName property.


2 Answers

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.

like image 133
Shawn de Wet Avatar answered Oct 02 '22 22:10

Shawn de Wet


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.

like image 28
Chris Phan Avatar answered Oct 02 '22 21:10

Chris Phan