问题
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.
回答1:
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.
回答2:
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.
回答3:
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 ->
Model Browser
window, then by opening up the tree.- Selecting the
Model
->Entity Types
then finding the target entity, and opening it up then selecting itsProperties
- 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.
回答4:
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
来源:https://stackoverflow.com/questions/14697423/mappingexception-edm-string-not-compatible-with-sqlserver-varbinary