MVC and repository pattern data efficiency
- by Shawn Mclean
My project is structured as follows:
DAL
public IQueryable<Post> GetPosts()
{
        var posts = from p in context.Post select p;
        return posts;
}
Service
public IList<Post> GetPosts()
{
        var posts = repository.GetPosts().ToList();
        return posts;
}
//Returns a list of the latest feeds, restricted by the count.
public IList<PostFeed> GetPostFeeds(int latestCount)
{
       List<Post> post - GetPosts();
       //CODE TO CREATE FEEDS HERE
       return feeds;
}
Lets say the GetPostFeeds(5) is supposed to return the 5 latest feeds. By going up the list, doesn't it pull down every single post from the database from GetPosts(), just to extract 5 from it?
If each post is say 5kb from the database, and there is 1 million records. Wont that be 5GB of ram being used per call to GetPostFeeds()?
Is this the way it happens? Should I go back to my DAL and write queries that return only what I need?