In Ward's article "The Breeze Server: Have It Your Way":
The typical business application has a minimum of 200 domain model types. 90+% of the time the shape of the data I'm sending over the wire is the same as the shape of the entity in my business model.
...
When the shape of a client entity doesn't align well with the shape of a server-side business entity, I may switch to a DTO for that particular case.
This hits the nail right on the head for our application, but what's the best way to switch just some entities for DTOs?
For example, our User entity contains sensitive properties that should not be exposed to the client. It also has related data that gets pulled from other systems and returned to the client, which ideally should just be extra properties on the client-side User objects. User seems an ideal candidate for switching to a DTO.
If User were an isolated entity this might be easier, but the problem is that User is referenced basically everywhere in the model. Almost every entity has a CreatedBy property, for example.
Is there a way to switch the User entity for a User DTO everywhere in the model? For all the other entities in the model that reference users, we still need to be able to load them with their user properties expanded, to query them on those user properties, and to save them with changes to those user properties.
I'm not sure how to do this other than building a big DTO model that is 95% identical to the entity model, and have some mapping code/framework to go between them. But, as Ward says in this post, "I don't like DTOs for every type; that's overkill that can ruin productivity."