From the code sample of this question, I added a string property to my wrapper, and then I only want it for GUI and tests purposes, I don’t want this string property to be persisted into the database. The wrapper looks the same as sampled in the linked question with this add-on:
public string StringValue {
get {
return stringValues[Value];
}
set {
if (stringValues.Contains(value))
t = (StreetType)stringValues.Single(s => s == value).IndexOf(value);
}
}
public static implicit operator string(StreetTypeWrapper w) {
return w == null ? stringValues[0] : w.StringValue;
}
public static implicit operator StreetTypeWrapper(string s) {
return new StreetTypeWrapper() { StringValue = s };
}
Not to mention that I never changed the StreetTypeMapping complex type mapping class to include this new property, I don’t want it in the database, but EF keeps persisting it anyway, though I only mapped the Value property of this complex type.
Is there something I do wrong for this to happen?
How can I avoid this annoying behaviour?
(EF decides for me what to map though I specified what to map)
you can add the
[NotMapped]attribute to the propertyif there is some way to make the property read-only, then EF will ignnore it also.