9

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Schanckopotamus
  • 781
  • 2
  • 6
  • 20

4 Answers4

23

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.

Schanckopotamus
  • 781
  • 2
  • 6
  • 20
5

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.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
4

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.

Asharkman
  • 43
  • 8
  • It works! 1)Update model from database 2)Itt will say some errors 3) Change those types in the Model 4)Update model from database (again) 5) It works – Tomi Nov 05 '16 at 11:47
1

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