Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MappingException Edm.String not compatible with SqlServer.varbinary

I am having a difficult time resolving a silly mapping problem. Basically what is going on is that I have a field in a sql db table that is a varbinary for the purposes of security (encryption and decryption). All that stuff is all well and good but it seems as though the edmx sees the field in that table as a string which I thought it should see it as given that the data is just a binary string. This is the error message I get.

Schema specified is not valid. Errors:

ReadModel.Model.msl(836,12): error 2019: Member Mapping specified is not valid. The type 
'Edm.String [Nullable=True,DefaultValue=,MaxLength=256,Unicode=,FixedLength=False]' of 
member 'field-in-question' in type 'Lib.ReadModel.TableName' is not compatable with
'SqlServer.varbinary' [Nullable=True,DefaultValue=,MaxLength=256,FixedLength=False]'
of member 'field-in-question' in type 'Model.Store.TableName'.

Has anyone had an issue like this? Maybe there is something I am overlooking? Maybe be able to point me in the right direction? I am having an issue on finding information to resolve the issue and am at a loss.

like image 818
Schanckopotamus Avatar asked Feb 04 '13 23:02

Schanckopotamus


2 Answers

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.

like image 77
Schanckopotamus Avatar answered Oct 02 '22 10:10

Schanckopotamus


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.

like image 44
ΩmegaMan Avatar answered Oct 02 '22 09:10

ΩmegaMan