Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:39:16+00:00 2026-05-14T07:39:16+00:00

My project is structured as follows: DAL public IQueryable<Post> GetPosts() { var posts =

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:39:16+00:00Added an answer on May 14, 2026 at 7:39 am

    As long as you’re working with IQueryable, query execution can be deferred. The query is executed once you call ToList() or do something else that requires data to be fetched (e.g. iterating over a child collection).

    I don’t think you need to worry about your DAL too much as I like to keep them fairly lean. You could take advantage of using deferred execution by rewriting your GetPostFeeds method though, e.g.:

    //Returns a list of the latest feeds, restricted by the count.
    public IList<PostFeed> GetPostFeeds(int latestCount)
    {
       var posts = repository.GetPosts();
    
       // Perform additional filtering here e.g:
       posts = posts.Take(5);
    
       return posts.ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Svn repository at http://svn.domain.com/project that is structured as follows: trunk/ build_file_1.xml
I'm developing on top of OpenLayers.js. My project folder is structured as follows: project
Greetings, My project structure is as follows: \- base (C static library) callbacks.h callbacks.c
The start of the structure is as follows... UITabBarController -> UINavigationController(s) From each of
In a project I am working on I am structuring my code as follows
Sorry for the long post... While being introduced to a brown field project, I'm
I have a maven project in eclipse with a folder structure are follows -
My project structure and files are as follows: project\HAL\hw_lcd.h project\HAL\hw_lcd.c project\project\app.c project\project\workspace.mcp project\project\workspace.mcw Where
I have a simple python application where my directory structure is as follows: project/
I am really confused i have a directory structure as follows. /foo/bar/project/ under project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.