Should viewmodel type property values ​​be null?

I have been making my viewmodel nullable properties for quite some time. My reasoning is that when a check occurs, I don’t want the default values ​​to be inserted into the fields that the user left empty, but they are necessary.

Of course, I mark the required fields as mandatory, but it made me think that I am losing a lot of fidelity in the object model by doing this.

Of course, my domain classes are NULL if they really can be null.

Should my viewmodel properties be null if a domain model is required?

+4
source share
1 answer

Should my viewmodel properties be null if a domain model is required?

Yes, they must correctly perform validation on the view model. When you verify that the view model is correct and map this view model to the actual domain model in your mapping layer, you will be sure that a value will be provided for this property.

+3
source

Source: https://habr.com/ru/post/1369236/


All Articles