MappingException Edm.String not compatible with SqlServer.varbinary

let me explain the problem, for example you've a table in database which has a entity called Price and you made its type string, and

during coding you define this entity as Property Int Price {get:set:}, NOW THAT IS THE PROBLEM. your datatype on SQL TABLE and Code must be same other wise this problem will occur.. this same problem I faced and I fixed it bye doing so, hope you'll get that

also change these types in EDMX Xml files by search if you are using EF

like

<Property Name="Price" Type="money" />

<Property Type="Decimal" Name="Price" Precision="19" Scale="4" />

Hope this will help some one


EF (or a user change at some point) had changed(?) the edmx's Model Entity for that property to be a Edm.String[Nullable=True,DefaultValue=,MaxLength=256,Unicode=,FixedLength=False] instead of a varbinary. The error reads local entity first followed by the database definition


Alternate Fix; Just As Viable

Yes your fix did resolve the problem...

But the problem could have also been properly resolved by setting the correct value in the edmx such as ->

  1. Model Browser window, then by opening up the tree.
  2. Selecting the Model->Entity Types then finding the target entity, and opening it up then selecting its Properties
  3. and changing the Type to a proper value.

enter image description here

The example above shows DateTime but in your case it would have shown String, which the error dutifully reported.


I had this issue, i changed a field type on the database and then my c# project start complaining. First I updated my my model from database. Then, i clicked on my model, my entity types, the table in question and the field/property. Then i changed the type of that to match the newly changed one in the table. The error went away then.


Ok, for those that ever have an issue like this it turns out that it seems to be best solved by deleting and re-adding the entity again in the edmx. It's a silly thing in my opinion, but it works. Bah.