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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:52:51+00:00 2026-05-16T19:52:51+00:00

I am storing transactions in a table. These transactions have an ID which relates

  • 0

I am storing transactions in a table. These transactions have an ID which relates to their parent node in a hierarchy tree. An example of my tree is shown in the image below. I need to allow an end user to retrieve the transaction and group them however they want as they are then written to a file based on the grouping. In the image below the devices (IM001-1 etc) create the transactions. In the live version the tree will be a lot larger and could have further levels for town and smaller regions etc. Now to the problem. Let’s say that a user wants all the transactions from the “UK” devices and they want them grouped by the country node (so “UK_North” and “UK_South”). The result should be a grouped list which in this example would contain two items. The first item would contain all the transactions from devices “IM001-1” and “IM001-2” and the second item would have the transactions for devices “IM002-1” and “IM002-2”. What I have done so far is to get a list of device for each parent node. So I have a grouped list where each item contains Ids of all its child devices. What I’d like to do is use Linq to look at all my transactions with their ID’s and create a grouped list where the grouping checks to see which parent owns it. This all sounds rather complex so if it’s not clear I can provide additional details if required. Am I approaching this problem the right way ? As there could be a lot of transactions I didn’t want to have to do a lot of tree navigation for every transaction because of the performance hit.

alt text

The transactions are held in a list of transaction:

 List<Transaction> transactions

There is a property on each transaction that exposes its “DeviceId”

I then have a grouped list which is defined as the following when I hover the mouse over the “var”:

 IEnumerable<IGrouping<String,Device>>

This list is called “groupedDevices”. Each item in the list represents a parent node (for example UK_North) which contains a list of all the available devices under that node. Each device has a “DeviceId” property.

What the Linq statement needs to do is look at the transactions list and see which parent it belongs to by using the “groupedDevices” list and then grouping by that.

  • 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-16T19:52:52+00:00Added an answer on May 16, 2026 at 7:52 pm

    Without knowing the classes you have, it’s hard to write the actual query, but something like this should work:

    from country in countries
    from device in country.Devices
    from transaction in device.Transactions
    group transaction by country
    

    Or:

    from country in countries
    select new
    {
      Country = country,
      Transactions = from device in country.Devices
                     from transaction in device.Transactions
                     select transaction
    }
    

    EDIT:

    For the structures you provided, you can use the following query:

    from g in groupedDevices
    from device in g
    from transaction in transactions
    where transaction.DeviceId == device.Id
    group transaction by g
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are currently storing plain text passwords for a web app that we have.
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I am storing a PNG as an embedded resource in an assembly. From within
I plan to be storing all my config settings in my application's app.config section
I'm storing a Word document in a SQL Server 2005 database in a varbinary(max)
We're storing some Guid's in a MS SQL database. There's some legacy code that
I'm storing an object ( TTF_Font ) in a shared_ptr that is provided to
I'm storing an ArrayList of Ids in a processing script that I want to
I am currently storing many different types of objects in the ASP.NET HttpRuntime.Cache and
I have a couple of tables that are transaction tables, and I would like

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.