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

The Archive Base Latest Questions

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

This question pertains to C#, LINQ grouping and Collections. I’m currently working on a

  • 0

This question pertains to C#, LINQ grouping and Collections.

I’m currently working on a grouping issue and I wanted to get some feedback from the community. I’ve encountered this particular problem enough times in the past that I’m thinking of writing my own data structure for it. Here are the details:

Suppose you have a grouping that consists of a manufacturer and products and the data structure is grouped by manufacturer. There are many manufacturers and many products. The manufacturers each have a unique name and id. The products may have similar names, but they do have unique ids. The proceeding list represents an example.

Ford 1, Fiesta 1945, Taurus 6413, Fusion 4716, F1 8749,

Toyota 2, Camry 1311, Prius 6415, Corolla 1117, Tacoma 9471

Chevrolet 3, Silverado 4746, Camero 6473, Volt 3334, Tahoe 9974

etc…

The data structure I would use to represent this would be

IEnumerable<Manufacturer, ManufacturerID, IEnumerable<Product, ProductID>>

but this doesn’t exist. So my question I want to ask the community is what data structure would you recommend and why?

Update:

I would like to keep the types anonymous and avoid the dynamic keyword. So the data structure would be something like

IEnumerable SomeDataStructure<T, U, V>

The other requirement is that is can have duplicated items. Here’s kind of what I’m thinking:

public class MyDataStructure<T, U, V>
{
    // make this like a list, not a dictionary
}

Update:

I decided to go with a Tuple data structure. It’s very powerful and easy to query against. The proceding code is how I ended up using it to create my manufacturer-vehicle relationships. The result is a nicely ordered data structure that has unique manufacturers ordered by name with their associated unique vehicles ordered by name.

public class ManufacturersVehicles
{
    public int ManufacturerID { get; set; }
    public string ManufacturerName { get; set; }
    public int VehicleID { get; set; }
    public string VehicleName { get; set; }
}

// "data" actually comes from the database. I'm just creating a list to use a mock structure to query against.
var data = new List<ManufacturersVehicles>
{
    { ManufacturerID = 1, Manufacturer = "Ford", VehicleID = 1945, VehicleName = "Fiesta" },
    { ManufacturerID = 1, Manufacturer = "Ford", VehicleID = 6413, VehicleName = "Taurus" },
    { ManufacturerID = 1, Manufacturer = "Ford", VehicleID = 4716, VehicleName = "Fusion" },
    etc...
};

// Get a collection of unique manufacturers from the data collection and order it by the manufacturer's name.
var manufacturers = data.Select(x => new { ManufacturerID = x.ManufacturerID, ManufacturerName = x.ManufacturerName })
                        .Distinct()
                        .OrderBy(x => x.ManufacturerName)
                        .Select(x => Tuple.Create(x.ManufacturerID, x.ManufacturerName, new Dictionary<int, string>()))
                        .ToList();

// Add the manufacturer's vehicles to it's associated dictionary collection ordered by vehicle name.
foreach (var manufacturer in manufacturers)
{
    // Get the collection of unique vehicles ordered by name.
    var vehicles = _alertDetails.Where(x => x.ManufacturerID == manufacturer.Item1)
                                .Select(x => new { VehicleID = x.VehicleID, VehicleName = x.VehicleName })
                                .Distinct()
                                .OrderBy(x => x.VehicleName);

    foreach (var vehicle in vehicles)
    {
        manufacturer.Item3.Add(vehicle.VehicleID, vehicle.VehicleName);
    }
}
  • 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-24T18:35:35+00:00Added an answer on May 24, 2026 at 6:35 pm

    MyDataStructure sounds very similar to a Tuple. See here for the three-generic parameter variant. Tuple gives a strongly typed container for a number of specified other types.

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

Sidebar

Related Questions

To all: This question pertains to some MS research I am doing. What I
This question pertains to query optimization using Linq with the Entity Framework. Is there
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question came up from what I see on a clients side: Intermittent Connection
This question arose when I was working on answering another question about best practices
thank you for your time, (As a side note, this question pertains mostly to
This is an efficiency/best practice question. Hoping to receive some feed back on performance.
This question pertains primarily to good design. Suppose I have a controller action like
NOTE: This question is tricky (to decide whether it pertains to SO or not),
I have a question that pertains to gathering events from tables in a calendar

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.