Why should a C# property getter not read from a DB?

后端 未结 7 816
深忆病人
深忆病人 2020-12-20 16:12

Some of the answers and comments to this question: Simplest C# code to poll a property?, imply that retrieving data from a database in a property\'s getter is Generally a Ba

7条回答
  •  难免孤独
    2020-12-20 16:20

    The Short Version: Making a property getter directly access a database would violate The Separation of Concerns principle.

    More Detail: Generally speaking, a property is intended to represent data associated with an object, such as the FirstName property of a Person object. Property values may be set internally or externally, but the act of modifying and retrieving this data on the object should be separated from the act of retrieving or committing that data to a permanent store.

提交回复
热议问题