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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:55:29+00:00 2026-06-04T03:55:29+00:00

I am struggeling a little with trying to write the LINQ query to do

  • 0

I am struggeling a little with trying to write the LINQ query to do the following,

public class MyClass
{
    public int ID {get; set;}
    public int Name {get; set;}
    public IEnumerable<string> SomeIEnumerable {get; set;}
}

I am trying to create the object using LINQ from a DB query that would return something as follows,

ID    Name     SomeString
0     NameA    "MyValue"
1     NameB    "Value1"
1     NameB    "Value2"
2     NameC    "Value"

The LINQ is pretty easy to write as well,

from DataRow row in dataSet.Tables[0].Rows
select new MyClass
{
    ID = (int)row["ID"],
    Name = row["Name"].ToString(),
    SomeIEnumerable = new List<string>{ row["SomeString"].ToString() }
};

The tricky part is how do I turn this into a Dictionary where
dictionary[1].SomeIEnumerable = {“Value1”, “Value2”}

A simple ToDictionary would throw an ArgumentException

The main issue here, is how do I handle the fact that the keyis not distinct, and be able to lookup in the temporary dictionary the existing value to add to it the values I am interested in.

  • 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-04T03:55:31+00:00Added an answer on June 4, 2026 at 3:55 am

    You can also your grouping, and then use IGrouping to retrieve the list of items in the group

    Sample code

        var simulatedData = Enumerable.Range(0,10).Select(x=> new {Key=x%3+1, Index=x}); 
        var dict = simulatedData.GroupBy(x=>x.Key).ToDictionary(x=>x.Key, x=>x.Select(t=>t.Index));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a parser class derived from the Python argparse ArgumentParser
Looking for a little help trying to get the value of two selected buttons,
I'm trying to get into C++ programming, and I'm quite struggling against the little
I'm trying (or rather struggling) to create a little Blackjack game. After some JavaScript
I am struggeling a little bit in fiding the proper googles Multimap implementation of
I am struggeling a little bit with some options for linking on a project
Hi i am struggling with the following i have knocked up a little sample
I'm trying to reflect an Android class, we know it can be done because
I'm a lisp beginner and I'm trying to write a package that defines a
I've started learning a little java, and am trying to accomplish what is likely

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.