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 8222385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:15:41+00:00 2026-06-07T14:15:41+00:00

I am trying to fetch business model entities from database and then iterate them

  • 0

I am trying to fetch business model entities from database and then iterate them to search a string. However, in my localhost this operation takes approximately 7 to 9 seconds for 500 objects.

public List<FileFolder> SearchFolders(int id, string searchString) 
{
    /* Placeholder that references folders that passes search criteria */
    List<FileFolder> addedFolders = new List<FileFolder>();

    /* Get the folder with specified id, also include Folders
     * that this folder has. No problem here works perfectly fine
     * and fast */
    FileFolder folder = dbSet.Include("Folders").
                             .Where(q => q.FileFolderID == id)
                             .ToList().FirstOrDefault();

    /* This takes too much time as I mention, up to 9 seconds
     * for 500 Folders */
    foreach (FileFolder f in folder.Folders)
    {
       if (f.Name.Contains(searchString))
       {
           addedFolders.Add(f);
       }

    }
    return addedFolders;
}

I am converting my fetched data to List so I can safely say all the data is now in memory? So foreach loop should not be making any more db calls while accessing folders. Also I have checked .Include method and it is is working fine.

What might be the cause of this slow iteration?

Thanks.

  • 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-06-07T14:15:43+00:00Added an answer on June 7, 2026 at 2:15 pm
    /* This takes too much time as I mention, up to 9 seconds
     * for 500 Folders */
    

    Remember, this is linq. Things don’t happen right away. It does not actually start running the query before the first iteration of the foreach().

    What is really slow in this query is this

    FileFolder folder = dbSet.Include("Folders").
                             .Where(q => q.FileFolderID == id)
                             .FirstOrDefault();
    

    The real question is how is dbSet’s “Folders” defined. Do you have lots of FK joins built in? If so a simple request like this can pull your whole database. It all depends on what depends on “Folders”.

    You can even see this in the debugger, as you step over the foreach loop you will see it “pop” back to the linq line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fetch multiple email addresses seperated by , within string from database
I'm trying to fetch random no. of entries from a database by using SELECT
I'm trying to fetch some data from a database. I want to select an
I am trying to fetch data from SQLite database(NSArray of strings) and populate the
I'm trying to fetch some email info from gmail using imap like this (BODY.PEEK[HEADER.FIELDS
I am trying to fetch the html source from this usl: http://books.google.com/books?id=NZlV0M5Ije4C&dq=isbn:0470284889 I used
I have this weird problem in java when trying to fetch records from MYSql
I'm trying to fetch associations of a model dynamically. For ex; model1 has_many model2s
I'm trying to fetch data from a page that resides on an intranet. The
I am trying to fetch a gzip from a URL and import it automatically

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.