If you really only retrieve a value from the database and not write it back, for example a read-only property, there is nothing wrong. Especially if a property cannot exist without its parent. However, when implemented, this can cause maintainability problems. You associate the process of retrieving stored information with access to this information. If you continue to follow this template for other properties and change the settings of your storage system, this change can spread throughout your code base. For example, changing the type of a table or column. This is why it is bad that you are calling the database at your destination.
On the side of the note: if the database throws an exception when trying to get the value, then it is obvious that there is an error in your code (or the calling client code), and the exception will still be displayed regardless of where you put the data access code. Multiple data is supported by some kind of collection inside the class that can throw exceptions, and standard practice is to store property values โโthis way (see EventHandlerList ).
Properties were designed specifically because programmers must perform additional logic when retrieving and setting values, such as validation.
For all that has been said, review your code and ask yourself: โHow easy will it change later?โ from there you should be on your way to a more convenient solution.
source share