MappingException Edm.String not compatible with SqlServer.varbinary

走远了吗. 提交于 2019-12-05 05:31:31

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.

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.

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!