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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:14:53+00:00 2026-06-15T10:14:53+00:00

I had a asked a previous question about generating a tree like structure which

  • 0

I had a asked a previous question about generating a tree like structure which culminated in this method:

    public ICollection<DefaultEventType> 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.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(row => row.Activity.Mission.Id)
            .Select(group => group.GroupBy(row => row.Activity.Id));

        return q2.Cast<DefaultEventType>().ToList();
    }

It fails on the return. I’ve done a ton of googling and searching the board. Obviously the types aren’t matching up because of something with the GroupBy, but I don’t understand exactly why this doesn’t work.

Can anyone provide insight or how I would go about fixing this?

Edit:
I’m trying to output a tree like structure. Currently it is looking like this:

* Parent1
    * Child1
        *ChildChild1

* Parent1
    * Child1
        * ChildChild2

* Parent1
    * Child1
        * ChildChild3

What I want it to do is group things like so:

* Parent1
    * Child1
        * ChildChild1
        * ChildChild2
        * ChildChild3
  • 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-15T10:14:54+00:00Added an answer on June 15, 2026 at 10:14 am

    Edit: OK, so you’re trying to return some kind of hierarchical structure rather than just a flat List<DefaultEventType>, so you’ll need to change your return type.

    It looks like your “Parent” is the Mission, “Child” is the Activity, and “ChildChild” is the DefaultEventType.

    Basically, you need two custom types:

    // Holds an Activity, and all the DefaultEventTypes corresponding to it.
    class ActivityWithEvents {
        public Activity Activity { get; set; }
        public IEnumerable<DefaultEventType> Events { get; set; }
    }
    
    // Holds a Mission, and all the Activities corresponding to it.
    class MissionWithActivities {
        public Mission Mission { get; set; }
        public IEnumerable<ActivityWithEvents> Activities { get; set; }
    }
    

    or something similar. You will need to change the signature of your method to

    public IEnumerable<MissionWithActivities> GetTierTree()
    

    and your return to

    var q2 = q.GroupBy(
        // First group the events by Mision
        e => e.Activity.Mission.Id,
        // For each mission found, select a MissionWithActivities
        (mid, events) => new MissionWithActivities {
            Mission = events.First().Activity.Mission,
            Activities = events.GroupBy(
                // Within the Mission, group the events by Activity
                e => e.Activity.Id,
                // For each Activity found, select an ActivityWithEvents
                (aid, events2) => new ActivityWithEvents {
                    Activity = events2.First().Activity,
                    Tasks = events2
                })
            });
    return q2.ToList();
    

    Now you can iterate through each MissionWithActivities, displaying it; and for each one, iterate through its ActivityWithEvents, displaying them; and for each one, iterate through its DefaultEventTypes, displaying them:

    foreach (var mwa in GetTierTree())
    {
        Console.WriteLine(mwa.Mission.Name);
        foreach (var awe in mwa.Activities)
        {
            Console.WriteLine("    " + awe.Activity.Name);
            foreach(var e in awe.Events)
                Console.WriteLine("        " + e.Name);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my previous question on this portal, I had asked about some insight about
A co-worker asked about some code like this that originally had templates in it.
I asked a question about this previously but my database structure has changed, and
I had asked a question about this earlier, but it didn't get answered right
In an interview they had asked an Question like this there are three overloading
This is a follow up to a previous question I asked about how to
This question is a follow-up to a previous question that I had asked: How
I had asked a question very much similar to this in the thread: https://stackoverflow.com/questions/11259474/store-the-numericals-in-char-array-into-an-integer-variable-in-vc
I had asked this question Adding more attributes to LINQ to SQL entity Now,
This is a link to a question I had asked two days back, How

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.