Hi all,
From one side, I want to write a killer app(in ASP.NET MVC) ;) But from the other side, I have many doubts if I should keep to so called "best practices" at all cost. So I have a design question and I really hope you can help me out.
Imagine a standard blog. I want to show 10 most recent posts. My database has standard
Posts, Categories, Tags, PostTags
tables. So as a natural consequence, my domain Post class has properties like this:
public Category Category { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
I use EF4 with POCO support. And I load the data with a standard query:
from p in context.Posts.Include("Category").Include("Tags")
select p
But why should I load the entire Post class (with for example those 2 properties), when on the page all I want to show (besides the post itself) are links to category and each tag, so all the columns I need are:
[Categories].[Name], [Categories].[Slug], [Tags].[Name], [Tags.Slug]
.
I don't need the entire Category or Tag instance (which may have 100 columns in corresponding table in the database)! I imagine that when a site gets a lot of requests, it DOES matter. So it would be nice not to load all columns (avoid scary SELECT *
).
I thought I can add a new class to my domain, say: ShortPost. But I feel it's not my domain! Post is the model, ShortPost is... well, just part of a complete Post. Besides - this ShortPost feels to me like modyfying/adjusting Domain (Model) just to please the View.
To sum up: should I really load the entire Model instance when on the View side I don't need the entire object? Can you please tell me about some preferred solutions/ways/etc?