DTOs are dumb objects consisting of public getters / setters. I usually put them in a separate namespace called SomeProject.Dto.
public class CustomerDto { public int Id { get; set; } public string Name { get; set; } public LocationDto HomeAddress { get; set; } }
Usually I try to keep property names the same between the DTO and the corresponding domain class, possibly with some smoothing. For example, my Client may have an Address object, but my DTO may have a smooth value:
public class CustomerDto { public int Id { get; set; } public string Name { get; set; } public string HomeStreet { get; set; } public string HomeCity { get; set; } public string HomeProvince { get; set; } public string HomeCountry { get; set; } public string HomePostalCode { get; set; } }
You can significantly reduce the number of duplicate display codes for translating domain objects in the DTO using Jimmy Bogard AutoMapper.
http://automapper.codeplex.com/
source share