Simplify Your Projections with AutoMapper: Listing 1.
Projecting data transfer objects into a focused ViewModel.
public class MainWindowViewModel
{
public string Name { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public void LoadCustomer()
{
// Load customer DTO from ORM (code elided)
this.Name = customerDto.Name;
this.Address1 = customerDto.Address1;
this.Address2 = customerDto.Address2;
this.City = customerDto.City;
this.State = customerDto.State;
this.Zip = customerDto.Zip;
}
}
About the Author
Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.