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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:37:30+00:00 2026-06-03T06:37:30+00:00

I have a database table like this: ## Settings ## ID (string) Value (string)

  • 0

I have a database table like this:

## Settings ##
ID (string)
Value (string)

The ID is a string like this Area.Category.SettingName.
I’m trying to build a menu structure based on the ID’s, so I would like it to be presented like this.

- Area
-- Category
--- SettingName

Data could be like this:

AreaOne.CategoryOne.MySetting
AreaOne.CategoryOne.MySecondSetting
AreaTwo.CategoryOne.MySetting
...

So to do this I tried to get all level one settings, and I tried that using this code:

List<Settings> settings = settings.GroupBy(x => x.ID.Split('.')[0]).FirstOrDefault().ToList()

And expected this result:

AreaOne
AreaTwo

But got this result:

AreaOne
AreaOne
AreaTwo

What am I doing wrong?

  • 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-03T06:37:32+00:00Added an answer on June 3, 2026 at 6:37 am

    If all you want is the level one settings, the correct query would be

    var delimiter = new[] {'.'};
    settings.Select(x => x.ID.Split(delimiter, 2)[0]).Distinct().ToList()
    

    This cuts off the L1 setting from each row and uses Distinct to make sure you only get each of them back once. There’s no need to use GroupBy unless you want to get aggregate information about each L1 setting (for example, if you want to get full information back from the database but grouped on L1 setting name because it’s convenient for some reason).

    I also used the overload of Split that takes a “limit” parameter because there’s no point in doing work that you are going to throw away.

    Finally, using a combination of FirstIndexOf and Substring would be even better performance-wise.

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

Sidebar

Related Questions

i have database table like this +-------+--------------+----------+ | id | ip | date |
I always forget how to do things like this. I have a database table
I have a table like this in my database (SQL Server 2008) ID Type
I have a database application in which a group is modeled like this: TABLE
I have written a function to print database table to an array like this
I have a database that contains a table that looks a bit like this:
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign
that my problem: I have database table like that: id (AI) market_id 1 6
Say I have a database table like the following: FileID | FileName | FileSize

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.