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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:01:25+00:00 2026-05-29T06:01:25+00:00

I am grouping a collection of tools using the following code: var filteredTools =

  • 0

I am grouping a collection of tools using the following code:

 var filteredTools = from t in tools
                               group t by new { t.ModuleName,t.Number}
                               into g
                               select new { ModuleName = g.Key, Values = g };

tools is a simple collection defined as follows:

List<Tool> tools

After grouping is performed I get 3 rows back (from 40 rows) so grouping is working. The rows have a key of g.Key and Values are the grouping conditions. Is there anyway to relate it back to the original tools. Maybe the key should be unique to each tool so after the grouping is performed I can fetch the original tool from the tools collection.

  • 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-29T06:01:26+00:00Added an answer on May 29, 2026 at 6:01 am

    Yes, the tools still exist within each group:

    foreach (var group in filteredTools) 
    {
        // This is actually an anonymous type...
        Console.WriteLine("Module name: {0}", group.ModuleName);
        foreach (Tool tool in group.Values)
        {
            Console.WriteLine("  Tool: {0}", tool);
        }
    }
    

    To be honest, you don’t really need your anonymous type here for the select. You could use:

    var filteredTools = tools.GroupBy(t => new { t.ModuleName,t.Number});
    foreach (var group in filteredTools) 
    {
        // This is actually an anonymous type...
        Console.WriteLine("Module name: {0}", group.Key);
        foreach (Tool tool in group)
        {
            Console.WriteLine("  Tool: {0}", tool);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to bind TreeView to the grouping collection ListCollectionView? code cs: ListCollectionView view=new ListCollectionView(Global._subjectCollection);
I have the following collection public IQueryable<myObjectType > GetWorkCellLoadGraphDataByIdDummy() { IList<myObjectType> workCellLoadGraphDataCollection = new
How would I create a nested grouping for the table below, using LINQ? I
I am wondering how should I be grouping my repositories? Like from the examples
Most programming languages use parentheses for grouping subexpressions. In Aklo, I'm using square brackets
I have collection of custom objects(assets) which I want to group with LINQ. Custom
Say I have a collection of object arrays of equal dimension, like this: var
I have an advanced datagrid, with the grouping collection attached to an XMLListCollection. I
I am using the PagedCollectionView for grouping. I have a DataGrid and a textbox
How can I do something like this in nHibernate: select count(*) from (subquery) 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.