Updating entity framework model after changing the data type of column in database table

2.8k Views Asked by At

I am working with entity framework 6 with database 1st approach. I changed the datatype of my columns in the table and after updating my model I got the following error:

Error 1 Error 2019: Member Mapping specified is not valid. The type 'Edm.Int32[Nullable=False,DefaultValue=]' of member 'Warranty' in type 'pjModel.Bill' is not compatible with 'SqlServer.nvarchar[Nullable=False,DefaultValue=,MaxLength=50,Unicode=True,FixedLength=False]' of member 'Warranty' in type 'pjModel.Store.Bills'.

what I understand that there is some compatibility issue between datatypes of framework and sql server. Also when I opened the .edmx file with XML viewer, it clearly shows that changes are propagated in the model i.e data type has been updated, but in the diagram view when I right click the particular column it still shows the old datatype.

I can provide more information if required.

2

There are 2 best solutions below

0
Amit Kaushal On

The issue has been resolved. I manually change the type from the diagram view and then it get mapped with the model class.

0
Dave Miller On

Same problem here, using EF6, after changing on a database table a field from int to bit.

It was not enought to delete property from model designer, and create it again, as the table mapping refered to the old type.

enter image description here

I guess this could be useful for similar cases. The only way to solve it (unless you don't mind deleting entity and updating model from database) is to edit your Entity Data Model as text (by default, DataModel.edmx), locate the entity as <Entity> node inside <Schema> node and find the desired property that indicates the old type. As an example:

<Property Name="MyProperty" Type="int" Nullable="false" />

Simply change Type attribute to the desired type, return to Visual Studio, save the edmx file, and rebuild.