If I were you, I would not use the domain model in my presentation layer. I would create a view model (another class) that would be very similar to my domain model. Then I used the automatic matching tool to match from my domain model to the view model.
This is a very common scenario, so if you use Google for the View and Domain models, you should find everything you need.
public class User { [Key] public int IdUser { get; set; } public string UserName { get; set; } public string Password { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } } public class UpdateUserViewModel {
Then you can configure auto-mapper to remove the boiler plate code:
public ActionResult ShowUser() { var domainModel = new User();
This is very rude, but I hope you get an idea.
Update 1: **
As I understand it, it’s better to create a new model for each view, and then match it with an entity
It’s not just better, it provides a better separation of problems, makes your code easy to check. Just looking at the class name, I see its purpose (UpdateUserViewModel, RegisterUserViewModel, etc.).
The source fields in this class must be validated metadata, and isn't it?
By original fields, I mean:
public class UserViewModel{ public string UserName { get; set; } public string FirstName { get; set; } }
These fields are already in your User class, so I saved my time without typing them again.
Will it be changing my model from MVC to MVVM or not beacuse do I still have a controller?
I suppose that I still suggested the MVC pattern, not MVVM.
Regarding Automaper, are you using github.com/AutoMapper/AutoMapper?
Automapper is what I used. There are several tools, and they do almost the same thing. Try a little and find the one that best suits your needs.
Good luck.