First of all i shall clarify that i am using Database First Approach using WEB API for a REST service. (Generally Developing The old fashioned way , and using the EF only for some features)
I have a model corresponding to a Database table let’s say
Model Client
--id
--owns
--address
--VAT number
--Credit card number
Model Session
--id
--clientID (FK)
--date
Now there are several times when i want to return only part of a model to the client, and some times combination of model data
{ClientName , Owns , LastSessionDate ) Or several other combinations
Only tactic that comes in mind is creating different models for each response (that comes with duplicate validation declarations etc).
Or when the response is only part of a model(Not a combination) Just nullify the fields i don’t want and tell the parser not to render null fields.
Is this the correct way or am i misconceiving something?
Typically I have a different model class for each response (or screen/view in a web app). Sometimes you can re-use these view models, but it’s usually more trouble than it’s worth.