c# - How to create a DTO in asp.net? -
1) want know recommended way create & return dto object has 10 attributes , want return 2 dto object.
2) should dto's have own namespace ? if yes, how organize them ? each dto inside single class file or dto's inside single class ?
please provide me sample code.
dtos dumb objects composed of public getters/setters. put them in separate namespace called someproject.dto.
public class customerdto { public int id { get; set; } public string name { get; set; } public locationdto homeaddress { get; set; } }
i try keep property names same between dto , corresponding domain class, possibly flattening. example, customer might have address object, dto might have flattened to:
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 dramatically reduce amount of repetitive mapping code of translating domain objects dtos using jimmy bogard's automapper.
Comments
Post a Comment