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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:16:31+00:00 2026-05-13T18:16:31+00:00

God, Linq confuses me… I’ve found quite a few examples that do similar things

  • 0

God, Linq confuses me… I’ve found quite a few examples that do similar things to what I need, but I’m still getting all turned around. I have a table (we’ll call it UngroupedTable) that looks like this…

ID, Val1, Val2
0001, A, 1
0001, B, 2
0002, C, 3
0003, D, 4
0003, D, 5

I want to use Linq to build a table where essentially in GroupedTable the IDs would become unique and values for duplicated IDs get concatenated into their respective rows.

So, it’d look like this…

ID, Val1, Val2
0001, A B, 1 2
0002, C, 3
0003, D, 4 5

We’ll call it GroupedTable.

What I’ve got certainly isn’t close, but I’ll post it anyway…

from row in passedInTable.AsEnumerable()
group row by new { ID = row.Field<string>("ID"), Val1 = row.Field<string>("Val1"), Val2 = row.Field<string>("Val2") } into groupedRow
select new
{
    ID = groupedRow.Key.ID,
    Val1 = groupedRow.Key.Val1,
    Val2 = groupedRow.Key.Val2
};

I think I could see how I could do what I need at this point with some for looping but I’m pretty sure it’s do-able via Linq. Especially based on all the examples I see out there, using .sum() for number types.

Edit
I guess the ultimate question is, in that query up above, how do I aggregate the values for the val1 and val2 columns from within that select new block so it’s selecting out the concatenated values.

  • 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-13T18:16:31+00:00Added an answer on May 13, 2026 at 6:16 pm

    You only need to group by the ID of the row. Then, concatenate all the values in each group:

    from row in passedInTable.AsEnumerable()
    group row by row.Field<string>("ID") into rowGroup
    select new
    {
        ID = rowGroup.Key,
        Val1 = String.Join(" ", rowGroup.Select(row => row.Field<string>("Val1")).ToArray()),
        Val2 = String.Join(" ", rowGroup.Select(row => row.Field<string>("Val2")).ToArray()),
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large project that is quite a mess. There's God classes, poor
God I hate the term code smell, but I can't think of anything more
Is it possible to share a single 'god' instance among everyone that links to
A colleague once said that God is killing a kitten every time I write
I was thinking many times, now days that we have Linq and other CLR
I came across God which seems good but I am wondering if anyone knows
This might be a god awful question but I'm not sure why it won't
This would be easier with a jsfiddle, but as god is my witness something
i know its not god to ask ms dos related questions now. but i
I have a class that I am monitoring using god. This is it's structure:

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.