I'm struggling to decide on a good way to structure my object model / web services in a webapp I'm working on. We have a common issue where different pages need a slightly different view of a standard object. For example, we have Team and an Organization types where an Organization can have one-to-many Teams. On one page all I need is something like
class Team {
long TeamID { get; set; }
string Name { get; set ;}
TeamType TeamType { get; set; }
}
But in another page I need a different projection of the data such as
class Team {
long TeamID { get; set; }
string Name { get; set ;}
string OrganizationName { get; set; }
string TeamPicture { get; set; }
}
Often times the projection of an object spans multiple tables. My thought is that it is bad to query out and pass around ALL of the data for a Team and Organization and then just use the parts I need on the page. It seems like I'll end up with huge amounts of unnecessary data being queried and flowing around the system.
My current model is to create separate types for each projection. I like the type safety but the problem I'm running into with this is I've got types like Team, SimpleTeam, TeamAndOrganization, etc. I'm using team/organization as the example, but I find the same problem with many different types in my system.
How do you handle this? I use WCF to pass data between the webapp and a back-end system.