Domain Model Vs View Model
In my view i need to display certain properties of said order.
Domain model vs view model. The relationship between them is that the vm knows about the dm not vice versa and the vm has extra stuff in it specifically for the view to use. A common scenario would be to add links. In any event they should not directly reference types from your domain model which will consist primarily of entities and value objects see ddd fundamentals for more on these concepts. If you need to change or enhance the dto then create a viewmodel.
It s ok to pass the dto to the view. You could expose the potentially dangerous properties in the view. So to conclude unlike domain model view and edit models are entities specifically used in the context of user interface also these are not some fixed technical terms which are set in stone some people call edit models as post model consider you have some kind of reports where you want to have employee details shown you may want to call it report model lastly there will be cases where you may want to use your domain model it self for viewing or editing its possible especially in small. I have my domain entities for this example i ll use order.
In most of the times our ui page presentation requirements are different from domain requirements. Components of mvvm pattern model model refers either to a domain model which represents real state content an object oriented approach or to the data access layer which represents content a data centric approach. It s also ok for the viewmodel to reference the dto as a complex property. Avoid using the domain model as the viewmodel.
Why we moving to view model. Citation needed view as in the model view controller mvc and model view presenter mvp patterns the view is the structure layout and appearance of what a user sees on. If you don t have a view with these requirements you don t need a view model at all. Here is the list of best practices and guidelines when using the viewmodel.
Public class orderviewmodel public datetime orderdate get. Keep domain model and viewmodel separate. These are the view model and domain model. The domain models are persisted to the database using the data access layer.
Client facing models typically reside in the ui layer as viewmodels or apimodels or they may be called dtos data transfer objects. Based on the requirement we add remove the attribute to the domain model. With mvc i m assuming i create a orderviewmodel like so. It s not a domain model but a viewmodel because a specific view uses it.
But the major difference between model and viewmodel is that view model is only used to rendering ie displaying information information in views.