I use several DTOs for each object. However, quite often, I donโt even have a predefined DTO for presentation, I just create an instance of an anonymous class, which is a projection of objects using Linq, and associates them with a graphical interface.
eg. showing a list of users
var users = ... // fetch from DB ViewData["users"] = users.Select( u => new { Id = u.Id, Name = u.First + " " + u.Last});
Display invoice:
var users = ... // fetch from DB ViewData["users"] = users.Select( u => new { Id = u.Id, Name = u.Last, Score = u.Score});
This saves me from creating two different DTOs. A potential drawback is that the view is not strongly typed, so depending on the version of ASP.NET MVC I need to declare the view model as dynamic or use some ExpandoObject tricks, but all this is perfectly hidden.
However, I always create DTOs for state changes and treat them as commands. Usually I have different DTOs for different operations on the entity, for example. ChangeUserAddressDTO , ChangeUserLevelDTO , etc.
source share