What does EntityFramework Code First do with property getters/setters?

风格不统一 提交于 2019-12-08 15:40:16

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/11962532/what-does-entityframework-code-first-do-with-property-getters-setters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!