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

  • SEARCH
  • Home
  • 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 6362315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:53:33+00:00 2026-05-24T23:53:33+00:00

I have a collection of 77 SPListItem objects. These objects can have an implied

  • 0

I have a collection of 77 SPListItem objects. These objects can have an implied recursive reference* to other objects. There are currently 4 levels in this hierarchy.

The issue that I’m running into is that when I get items that are deeper in the hierarchy it takes surprisingly long to retrieve them. Time I am seeing at each level:

zeroth: nearly instant
first: 2 seconds
second: 20 seconds
third: goes for about a minute and then times out

This is the structure of the fields in the SPListItem objects:

ID
Title
ParentId //recursive field

And this is the code I am using to get the SPListInformation at each level:

SPList navList = SPContext.Current.Web.Lists["NavStructure"];

//Get items that have no parent
var zero = from n in navList.Items.Cast<SPListItem>()                                                 
           where ((SPFieldLookupValueCollection)n["Parent"]).Count == 0                               
           select new { ID = n.ID, Title = n.Title };

//Get first level items
var first = from n in navList.Items.Cast<SPListItem>()
            from z in zero
               where ((SPFieldLookupValueCollection)n["Parent"]).Select(t => t.LookupId).Contains(z.ID)
            select new { ID = n.ID, Title = n.Title, ParentId = z.ID};
lv_First.DataSource = first.ToList();
lv_First.DataBind();

//Get second level items
var second = from n in navList.Items.Cast<SPListItem>()
             from z in first
               where ((SPFieldLookupValueCollection)n["Parent"]).Select(t => t.LookupId).Contains(z.ID)
             select new { ID = n.ID, Title = n.Title, ParentId = z.ID};
lv_Second.DataSource = second.ToList();
lv_Second.DataBind();

//Get third level items
var third = from n in navList.Items.Cast<SPListItem>()
            from z in second
             where ((SPFieldLookupValueCollection)n["Parent"]).Select(t => t.LookupId).Contains(z.ID)
            select new { ID = n.ID, Title = n.Title, ParentId = z.ID};
lv_Third.DataSource = third.ToList();
lv_Third.DataBind();

Can anyone see something that I am doing here that could cause the long run times that I am seeing?

If anyone would like to see the data just let me know. I left it out because it would be a bit lengthy.

*When I say “implied recursive reference”, I mean there is a member in each SPListItem object that can contain an ID and that this ID references another object in the list, but this relationship is not enforced.

  • 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-24T23:53:34+00:00Added an answer on May 24, 2026 at 11:53 pm

    Well, you’re executing the first query for each item in navList in second… and each time you execute the first query you’re executing the zero query for each item in navList again. third does it all again for every item.

    Just adding a call to ToList at the end of each of those queries would probably speed it up significantly.

    It’s not really clear what you’re trying to do, but it feels like you could probably make this rather quicker using a Dictionary or Lookup rather than iterating over the whole collection each time you want to find something.

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

Sidebar

Related Questions

I have one logical question. I have collection of employee objects There are 3
I have Collection List<Car> . How to compare each item from this collection with
I have a collection of objects to which I'd like to just add a
I have collection of patient in a lists named lst_Patient. And this is method
I have collection of custom objects(assets) which I want to group with LINQ. Custom
I have a collection which contains two type of objects A & B. Class
I have a collection where each document looks like this {access_key:'xxxxxxxxx', keyword: banana, count:12,
I have a collection of Calendar objects. Calendar has a property Id . IEnumerable<Calendar>
For example, I have collection with documents, where documents can have field url (but
Why is there Apache's Synchronized Set when we have Collection's SynchronizedSet ? Is it

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.