Lately I've been hearing a lot about DTOs and how useful they are but I can't find a good example of using it in ASP.NET context.
Let's say I use three tier architecture:
Where should I convert from the EF Employee object to an EmployeeDTO POCO?
Lets say I do the conversion in the Data Access layer but what happens in the WCF service? Should it then be converted to another DataMember
object and when it get's to the UI layer(MVC web app) should it then be converted for the third time to a model? I would appreciate it if someone could please clear this for me
In similar situation I used to put dto's into Core which is known to all three. So you have
Core | ------------ | | | DAL BL PL
Each layer can operate with Core.Dto.Employee
. Each layer also exposes Core.Dto.Employee
externally in its API. But internally each layer can transform/adapt Core.Dto.Employee
, e.g. you read from database EF.Employee
and later convert it to Core.Dto.Employee
. Transformation is contained by the layer's boundary.
If you have several different models to represent same thing throughout the layers, for example PL wants PL.Employee
and DAL operates on EF.Employee
, you will end up with a mess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With