What exactly does the EntityFramework do to map properties that have custom getters and setters when using Code First?
Does it simply call the getter for a property when serializing, and the setter when deserializing? So I could do something silly like...
public class Foo {
public DateTime TimeAccessed {
get {
return DateTime.Now;
}
set {
TimeDeserialized = DateTime.Now;
}
}
[NotMapped]
public DateTime TimeDeserialized { get; private set; }
}
Note I have no actual interest in using the above code, or anything like it... it's for illustrative purposes only.
Also, when mapping a property with Code First, do all getters and setters need to be public
?
Yes; EF does call the getters and setters.
It would actually be impossible for EF to work in any other way.
No; they can even be private. (although the property itself must be public)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With