views:

260

answers:

1

I can either have the data elements in the viewmodel (partial code):

public class PersonViewModel : INotifyPropertyChanged
{
    public string FirstName
 {
  get
  {
   return firstName;
  }

  set
  {
   firstName = value;
   OnPropertyChanged("FirstName");
  }
 }

 public string LastName
 {
  get
  {
   return lastName;
  }

  set
  {
   lastName = value;
   OnPropertyChanged("LastName");
  }
 }

}

or I can wrap them as a DTO inside the view model (partial mode):

public class PersonDTO : INotifyPropertyChanged
{
    public string FirstName
 {
  get { return firstName;}

  set
  {
   firstName = value;
   OnPropertyChanged("FirstName");
  }
 }

 public string LastName
 {
  get { return lastName; }

  set
  {
   lastName = value;
   OnPropertyChanged("LastName");
  }
 }

}

public class PersonViewModel 
{
    public PersonDTO boundToPerson;
}

which approach is better and why?

+1  A: 

Hi Ali

Assuming that your model is essentially your DTO and isn't being used anywhere else. I would go with the first option.

So you would simply Map from your Source Entity to the model. In which case the DTO is unnecessary as the Model would be the "flattened" simple translation you would use in your strongly typed View.

Good luck!

5x1llz