INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Dynamic GroupBy

Dynamic GroupBy

(OP)
Hello! I was hoping someone could tell me if there is a better, more efficient way to go about this. Basically, here is the situation. I have a program that has a DataTable. Using a settings file, I need to be able to group by multiple columns.

To give an example.. maybe the settings file is xml with something like:

CODE --> XML

...
<GroupingColumns>
    <Column>employee_number</Column>
    <Column>clock_OUT_date</Column>
    <Column>job_number</column>
</GroupingColumns>
... 

I already know how to read in the XML properly and all of that, and how to do basic LINQ GroupBy, but what I need to do is find a way to dynamically decide which columns that it should group by. Right now the way I'm doing it works... but it really seems ugly and inefficient. Essentially I'm juggling a list of lists of rows. Initially the list of lists just contains a single list of rows, so something like:

CODE

list
{
    list
    {
        row
        {
            employee_number = 1,
            clock_OUT_date = 8-25-2013,
            job_number = 1,
            hours = 10
         },
         row
         {
             employee_number = 1,
             clock_OUT_date = 8-26-2013,
             job_number = 2,
             hours = 10
          }
          row
          {
             employee_number = 2,
             clock_OUT_date = 8-25-2013,
             job_number = 1,
             hours = 8
          }
    }
} 

Now, if I were to run, say, GroupBy(job_number) I would end up with a list of two lists of rows, so...

CODE

list
{
    list
    {
        row
        {
            employee_number = 1,
            clock_OUT_date = 8-25-2013,
            job_number = 1,
            hours = 10
         },
          row
          {
             employee_number = 2,
             clock_OUT_date = 8-25-2013,
             job_number = 1,
             hours = 8
          }
    },
    list
    {
         row
         {
             employee_number = 1,
             clock_OUT_date = 8-26-2013,
             job_number = 2,
             hours = 10
          }
    }
} 

So every time you do another group by, it goes into each group and generates a new set of lists which get added back to the root list of lists...


Just talking about the way I'm doing it makes me a bit confused trying to keep track of it. This seems ugly to me... anyone know of another way to do this? I can really see this causing me to pull some hair out...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close