Home  /  Questions  /  Question

50   50
Sep 21, 2015

Why not use DTO?

BusinessObjects from WinForms of Patterns In Action4.5
Why do you need to Mapper.CreateMap work to define the MemberModel / OrderDetailModel / OrderModel from the Model folder?

Sample :
\Patterns in Action\WinFormsApp\Models\Model.cs

Current :
        public MemberModel GetMember(int memberId)
            var member = service.GetMember(memberId);
            return Mapper.Map<Member, MemberModel>(member);

My Coding :  DTO (http://corej2eepatterns.com/Patterns2ndEd/TransferObject.htm)
        public Member GetMember(int memberId)
            return service.GetMember(memberId);

Why do not use DTO?


508   99.9
Sep 26, 2015
Hello Ji: 

In our example the Member Business Object is mapped to a Member Model which is a DTO.

In your example the Business object is returned, which may or may not be a DTO (if it has methods it is not considered a DTO).
But if it is a DTO then your example is just fine.  

In fact, if it not a DTO is would also be fine. DTO is a 'best practice' but not absolutely necessary.

Hope this helps.

 1 comment
Thank you so much --- Ji Hyeonmyeong  Sep 30, 2015