I have a WCF service and just created a DTO for a business object.
My question is where to put the comparison between the two?
A) In the DTO?
public class PersonDTO { [DataMember] public string Id { get; set; } [DataMember] public string Name { get; set; } public void CloneFrom(Person p) { Id = p.Id; Name = p.Name; } public void Populate(Person p) { p.Id = Id; p.Name = Name; } }
or
B) In a business object?
public class Person { public string Id { get; set; } public string Name { get; set; } public void CloneFrom(PersonDTO dto) { Id = dto.Id; Name = dto.Name; } public PersonDTO GetDTO() { return new PersonDTO() { Id = Id; Name = Name; } } }
I like the separation of problems in (the business object does not know DTO), but I prefer the encapsulation of B (there is no need to expose the guts of business objects in the DTO).
Just thought, is there a standard way?
source share