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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:51:47+00:00 2026-06-05T11:51:47+00:00

I have a backend table as shown below and I am reading it using

  • 0

I have a backend table as shown below and I am reading it using ado.net.

I tried to convert this to a dictionary with key value pair, but I don’t know how to map keys and values so that when I read code 1 I can return its category name, and when I read 2 as code 3 as subcode I can read both its corresponding category and subcategory?(Say ex., Old, ThreeMonth).

Is there any other type/class available to acheive this functionality?

code    Sub_Code    Category    Sub_Category
1             1     NEW                  NEW
2             1         Old             OneMonth
2             2         Old                 TwoMonth
2             3         Old                 ThreeMonth
2             4         Old                 Ninemonth
5             4     APPOINTMENT         APPOINTMENT MADE
9             4         Invalid             LANGUAGE BARRIER
  • 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-05T11:51:49+00:00Added an answer on June 5, 2026 at 11:51 am

    You have a number of options, depending on what operations you need to do with the data, how often it changes, etc. Some obvious ones are:

    Nested Types

    Create a custom type to hold your category and its sub-categories. This has the benefit that you can skip the sub-categories if there are none, and your data type can exactly map to your business object.

    public class Category 
    {
      public int Id;
      public string Name;
      Dictionary<int, string> Subcategories = new Dictionary<int, string>();
    }
    
    Dictionary<int, Category> Categories;
    

    (I’d also consider a KeyedCollection here that can extract the Id from a Category as the key directly.)

    The downside: its a bit more work to add or retrieve a subcategory because you have to do two lookups:

    var subcategory = Categories[1].Subcategories[1];
    

    A 4-Tuple (quadruple?)

    If your data structure rarely changes you can use a 4-field Tuple<>:

    List<Tuple<int, int, string, string>> Categories;
    var subcategory = Categories.Where(x => Item1 == 1 && Item2 == 1);
    

    The biggest downside here is that it’s not indexed very well. You could alleviate that a bit, at the cost of even more complexity, by using two Tuples (one key, one value):

    Dictionary<Tuple<int, int>, Tuple<string, string>> Categories;
    

    But IMO that gets kinda messy, and at that point I’d just go with a custom class.

    Split Collections

    Split up the category name and subcategories into separate collections: one holds the cateogory id -> name mapping, and the other holds the category id -> subcategory mapping:

    Dictionary<id, string> CategoryNames;
    Dictionary<id, Dictionary<id, string>> Subcatgories;
    

    This is more flexible than the Tuple solution but doesn’t involve a custom data type, so it’s a more “quick and dirty” solution. Also, if you commonly find yourself only caring about one or the other, having the data separate may make things more efficient.

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

Sidebar

Related Questions

i have an asp.net mvc website with a SQL server backend. For every table
I have a asp.net-mvc website with a SQL server backend (using nhibernate for OR
I have an asp.net/C# application and backend as oracle. I need to use transactions.
I have implimented the example: http://www.datatables.net/examples/server_side/server_side.html only to discover that this example gets all
I have a database with the following table: id value ----------- 1 yes 2
I have a table defined like this: CREATE TABLE mytable (id INT NOT NULL
I have a backend class that has to raise an event with no arguments.
I use subversion to manage my yii website (php framework) and have separate backend
I have a Flash app with a PHP backend. Whenever there is a PHP
I have the following in nginx: # backend location /backend/ { deny all; }

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.