Hello guys,
I would like to get an insight into your daily work :P
How do you read the Person data into the PersonViewModel ?
Is it just a
PersonViewModel pVM = staticHelper.ConvertPersonToPersonViewModel(person);
or is there something cooler?
Hello guys,
I would like to get an insight into your daily work :P
How do you read the Person data into the PersonViewModel ?
Is it just a
PersonViewModel pVM = staticHelper.ConvertPersonToPersonViewModel(person);
or is there something cooler?
Some folks advocate copy constructors.
Others might use reflection to copy properties.
Of course, nothing says you can't use reflection to copy properties while in a copy constructor.
Simply include the Person object in the view model, don't try to copy the object at all.
public class PersonViewModel
{
public Person Person { get; set; }
... plus other properties your view model might need
}
then in your controller:
PersonViewModel pVM = new PersonViewModel { Person = person } ;
Automapper is the best thing since the for loop, maybe even the if statement.
I think you're misunderstanding the point of the viewmodel. The viewmodel is supposed to be a mapping / interface to the model, not a copy of it.