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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:19:57+00:00 2026-06-18T01:19:57+00:00

I have three data types in a Parent -> Child -> Grandchild relationship as

  • 0

I have three data types in a Parent -> Child -> Grandchild relationship as follows:

Mission -> Activity -> Project

where they contain the parent IDs for relation (i.e. ‘Project’ contains an ‘Activity’ ID). I have some code I use to generate a jQuery nested accordion setup so the the user can click on a ‘Mission’ to see related ‘Activity’s, and can then click on an ‘Activity’ to see the related ‘Project’s.

The code I have takes about six seconds from hitting the page to grab the data from the database and then populating the page. This is far too long and would like to optimize my code in anyway possible. Using miniprofiler (miniprofiler.com) I can see it makes 131 calls to the database with a lot duplicate calls but I’m sure why.

Any help you can give me is greatly appreciated!

LINQ query I use to get all the data and organize it:

public IEnumerable<MissionWithActivities> GetTierTree()
{
var q = from mission in _context.tMissions
        join activity in _context.tActivities on mission.id equals activity.missionId
        join project in _context.tDefaultEventTypes on activity.id equals project.activityId
        where !project.isRemoved && project.defaultCategoryId == 4
        orderby mission.id, activity.id, mission.name
        select new DefaultEventType(project.tierLevel.TryParseEnum<GanttType>(GanttType.Unknown), DefaultCategoryRepository.CreateFrom(project.tDefaultCategory))
        {
            AllowNumericSuffix = project.allowNumericSuffix,
            AttachMilestoneMoniker = project.attachMilestoneMoniker,
            Description = project.description,
            Id = project.id,
            IsReadOnly = project.isReadOnly,
            IsSticky = project.isSticky,
            Name = project.name,
            Sid = project.sid,
            Style = project.style.TryParseEnum<GanttElementStyle>(GanttElementStyle.Unknown),
            TimeStamp = project.createdDT,
            UpdatedTimeStamp = project.updatedDT,
            Activity = new Activity { Id = activity.id, Name = activity.name, Mission = new Mission { Id = mission.id, Name = mission.name } }
        };
var q2 = q.GroupBy(
    e => e.Activity.Mission.Id,
    (mid, events) => new MissionWithActivities
    {
        Mission = events.First().Activity.Mission,
        Activities = events.GroupBy(
            e => e.Activity.Id,
            (aid, events2) => new ActivityWithEvents
            {
                Activity = events2.First().Activity,
                Events = events2
            })
    });
return q2.ToList();

}

Code-behind I use to initially populate a datalist and then the nested accordions:

public void SetTierTree(IEnumerable<MissionWithActivities> tierList)
{
dlMission.DataSource = tierList;
dlMission.DataBind();
}
public void dlMission_ItemDataBound(Object sender, DataListItemEventArgs e)
{
DataListItem item = e.Item;
MissionWithActivities mwa = (MissionWithActivities)item.DataItem;
var dlActivity = (DataList)item.FindControl("dlActivity");
dlActivity.DataSource = mwa.Activities;
dlActivity.DataBind();
var i = 0;
foreach (var project in mwa.Activities)
{
    DataListItem pItem = dlActivity.Items[i];
    var lbCreateNewProject = (LinkButton)pItem.FindControl("lbCreateNewProject");
    lbCreateNewProject.CommandArgument = project.Activity.Id.ToString();
    var dlProject = (DataList)pItem.FindControl("dlProject");
    dlProject.DataSource = project.Events;
    dlProject.DataBind();
    i++;
    var j = 0;
    foreach (var data in project.Events)
    {
        DataListItem lblItem = dlProject.Items[j];
        var lbEditProject = (LinkButton)lblItem.FindControl("lbEditProject");
        var lbRemoveProject = (LinkButton)lblItem.FindControl("lbRemoveProject");
        lbEditProject.CommandArgument = data.Id.ToString();
        lbRemoveProject.CommandArgument = data.Id.ToString();
        j++;
    }
}
}

This is the .aspx page with the jQuery (I didn’t remove the .net so it won’t run) but I wanted to include the code for your perusal:

$(document).ready(function () {
        $("html").addClass("js");
        $(".row").mouseover(function () { $(this).addClass("over"); }).mouseout(function () { $(this).removeClass("over"); });
        $('h5').click(function () { $(this).prev(".heading_add").toggle(); });
        $(".row:even").addClass("alt");
        $.fn.accordion.defaults.container = false;
        $(function () {
            $("#acc1").accordion({
                el: ".h",
                head: "h4, h5",
                next: "div",
                initShow: "none"
            });
            $("html").removeClass("js");
        });
    });
<div id="main">
        <ul id="acc1" class="accordion">
        <asp:DataList ID="dlMission" runat="server" style="width:600px;">
        <ItemTemplate>
            <li>
                <h4><%# Eval("Mission.Name") %></h4>
                <div class="inner">
                    <ul>
                    <asp:DataList ID="dlActivity" runat="server">
                    <ItemTemplate>
                        <li>
                          <asp:LinkButton ID="lbCreateNewProject" CausesValidation="false" CssClass="heading_add" runat="server" Text="[ + ] Add New Project Type" OnCommand="lbCreateNewProject_OnCommand" />
                          <h5><%# Eval("Activity.Name") %></h5>
                          <div class="inner">
                          <asp:DataList ID="dlProject" runat="server">
                          <ItemTemplate>
                            <div class="row">
                              <%# Eval("Name") %><div class="action_buttons"><asp:LinkButton ID="lbEditProject" CausesValidation="false" runat="server" Text="Edit" OnCommand="lbEditProject_OnCommand" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:LinkButton ID="lbRemoveProject" CausesValidation="false" runat="server" Text="Remove" OnCommand="lbRemoveProject_OnCommand" /></div><br />
                            </div>
                          </ItemTemplate>
                          </asp:DataList>
                          </div>
                        </li>
                    </ItemTemplate>
                    </asp:DataList>
                    </ul>
                </div>
            </li>
        </ItemTemplate>
        </asp:DataList>
        </ul>
    </div>

For the curious I am using the jQuery.nestedAccordion.js plugin to do this.

  • 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-18T01:19:59+00:00Added an answer on June 18, 2026 at 1:19 am

    I figured out the main cause of the slowness I was experiencing had to do with the way LINQ works. My main issue was this in the LINQ query:

    DefaultCategoryRepository.CreateFrom(project.tDefaultCategory)
    

    The CreateFrom function was causing LINQ to grab all data associated with DefaultCategory which was extensive. I was unaware that LINQ would grab every relationship all the way down the tree and return it whether it was being used or not. You can read about it here for more info:

    http://msdn.microsoft.com/en-us/library/bb738633(v=vs.100).aspx

    MiniProfiler still says a duplicate call is being made 131 times, but I think that has to do with the way .Net runs things, if I step through the code it only hits the query once so still working that part out.

    Hope this helps someone!

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

Sidebar

Related Questions

I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I have three tables. I have to retrieve the data using Linq statement. My
I have three select boxes :- select1 select2 select3 , i am fetching data
In the /data directory of solr, suppose, I have three folders named as index,
In my application, I have three collection objects which store data. The data which
Ok, here's the condensed form. I have three main tables to draw data from:
I have a three column workbook with the following data: Col A: Names Col
I have following data type typedef std::map <std::string.std::string> leaf; typedef std::map <std::string,leaf> child; typedef
I have child categories (cities) which belongs to parent categories (countries). I get a
I know that in elasticsearch, we can have child/parent relationships between documents. And then,

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.