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.

3
  • 2
    There IS a binary type in the Type Dropdown in the EDMX designer. Did you try that? Commented Feb 4, 2013 at 23:18
  • sorry it tool a little while for a reply but I am currently unaware of a "type" dropdown in the EDMX designer. I'll do some looking around into this and see what I can come up with. Thnx Commented Feb 5, 2013 at 15:26
  • Screenshot Commented Feb 5, 2013 at 15:30

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Simple solution that works in some cases. Try this first before wasting time digging through your code.
It could be a hack but not a solution.
this solution (deleting) works with many issues when it comes to EF. Update almost useless
I usually delete the whole edmx but this time I just deleted and re-added the models in which I was getting error.
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.

Comments

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.

1 Comment

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
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.