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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:01:36+00:00 2026-05-23T02:01:36+00:00

This is the data in my database table: That’s my business object: public class

  • 0

This is the data in my database table:

enter image description here

That’s my business object:

public class Unit
    {
        public Unit()
        {
            MemberIdList = new List<String>();
        }

        public String UnitType { get; set; }
        public String UnitZoom { get; set; }
        public String MemberZoom { get; set; }

        public List<String> MemberIdList { get; set; }
    }

The whole data from database is fetched and put into a DataTable.

Now comes the Linq Transformation…

After I return a List with 3 Unit objects holding this data:

enter image description here

Now guess how I got the data into the 3 business objects…
that’s the way I would like to know. A hint might be Distinct and IEqualityComparer for the 3 properties…
just an assumption…

UPDATE

Question updated:

Please read the comment in the code 🙂

var groupedCollection = table.AsEnumerable()
                                    .GroupBy(row => new
                                    {
                                        UType = row.Field<string>("UnitType"),
                                        UZoom = row.Field<string>("UnitZoom"),
                                        MZoom = row.Field<string>("MemberZoom"),
                                        MOrder = row.Field<int>("MemberOrder"), 

// I DO NOT WANT the MemberOrder to be in the Group Key, but later on I use this Property to order by it…
});

            var unitCollection = groupedCollection
                                .Select(g => new Unit 
                                {
                                    UnitType = g.Key.UType,
                                    UnitZoom = g.Key.UZoom,
                                    MemberZoom = g.Key.MZoom,                                   
                                    MemberIdList = g.Select(r => r.Field<string>("MemberId")).OrderBy(b => g.Key.MOrder).ToList(),
                                });

            List<Unit> units = unitCollection.ToList(); 
  • 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-23T02:01:37+00:00Added an answer on May 23, 2026 at 2:01 am

    Something like this ?

    DataTable dt = ...
    
    var list = 
    dt.AsEnumerable()
    .GroupBy(r => new
    {
        UType = r.Field<string>("UnitType"),
        UZoom = r.Field<string>("UnitZoom"),
        MZoom = r.Field<string>("MemberZoom")
    })
    .Select(g => new Unit 
    { 
        UnitType = g.Key.UType, 
        UnitZoom = g.Key.UZoom, 
        MemberZoom = g.Key.MZoom ,
        MemberIdList = g.Select(r => r.Field<string>("MemberId")).Distinct().ToList()
    })
    .ToList();
    

    EDIT:
    the call to .Distinct() is not strictly necessary. It avoids duplicated MemberIds if you can have them, but it really depends on what OP needs.

    EDIT2:
    (according to the last question update)

    You are close to the solution:

    just change this line of my code:

    MemberIdList = g.Select(r => r.Field<string>("MemberId")).ToList()
    

    to:

    MemberIdList = g.Select(r => r.Field<string>("MemberId")).OrderBy(r => r.Field<int>("MOrder")).ToList()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to update data in database table. Can reuse same code
I have data in an MYSQL database that looks like this: Project Date Time
I have a datalogging application (c#/.net) that logs data to a SQLite database. This
I've got a database table that stores images as varbinary(max). This works great for
I want to have a database table that keeps data with revision history (like
I want to select data from a database table that is not part of
I have this big database table that tracks (currently in production), a persons medical
I have a database table that contains Swedish/Norwegian strings. When I query some data,
I have a database with a table that records data coming from various sources.
I have a database table that contains collection data for product collected from a

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.