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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:50:55+00:00 2026-05-18T00:50:55+00:00

I have seen quite a few ways to get dynamic LINQ to work for

  • 0

I have seen quite a few ways to get dynamic LINQ to work for the .GroupBy, but every one that I see seems to expect a hard coded entity. I want to reproduce the following as dynamic LINQ:

//need dynamic LINQ for this
var groupedRows = rows.GroupBy(z => new { make = z["make"], model = z["model"] })
                      .Select(x => x.Key);

I’d like to be able to just do this, making the entire function a string:

var groupedRows = rows.GroupBy(z => "new { make = z[\"make\"], model = z[\"model\"] }")

I realize that if it were only a regular entity, I could do this

mylist.GroupBy(z => new { make = z.make, model = z.model }).Select(x => x.Key);

If I had that regular entity, I could use Mitsu’s dynamic GroupByMany.

I am trying to get this to work with a regular datatable (not strongly typed). Any ideas?

  • 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-18T00:50:56+00:00Added an answer on May 18, 2026 at 12:50 am

    Ok, I was able to get this working with both reflection and compiling code at runtime using the Mono Compiler as a Service (MCS). Utilizing the question Injecting a variable into the Mono.CSharp.Evaluator (runtime compiling a LINQ query from string), I came up with the following solution (#2 in the answer to that question):

    DataTable dt = GetData();
             var dataRows = dt.AsEnumerable();
    
             //Initializing the evaluator  
             Evaluator.Init(new string[0]); 
              Evaluator.ReferenceAssembly(Assembly.GetAssembly(typeof(DataRow)));
              Evaluator.ReferenceAssembly(Assembly.GetExecutingAssembly());
    
             Evaluator.Run(@"using System;  
               using System.Linq;  
               using System.Collections.Generic;
               using System.Data;
               using MyNamespace;");
    
             var func = (Func<DataRow, object>)Evaluator.Evaluate(@"new Func<DataRow,object>(z => new
                    {
                        make = z[""make""],
                        model = z[""model""]
                    });");
    
             dataRows.GroupBy(func).Select(x => x.Key);
    

    So that compiles the function at runtime, then calls the function in the GroupBy for each row. When I needed the value of make or model, I then needed to use reflection to get to that value through my GetPropertyValue extension method.

    I still can’t get LINQ working within the MCS, even after following the Mono Compiler as a Service (MCS) question, but just using it to creating the function did what I needed it to do.

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

Sidebar

Related Questions

I have seen quite a few ways to output variables. Which of these ways
I have seen quite a few code samples/plugins that promote uploading assets directly to
I have seen the reverse of this question quite a few times, but have
I have seen quite a few examples/tutorials on the web for doing one-one shared
I have seen in quite few places (one example here: http://pascalgamedevelopment.com/archive/index.php/t-1204.html ) people doing
I have seen a few sites now that use SIFR, and I can see
I have seen quite a few questions about this but cant seem to find
I've seen quite a few threads about ClassNotFoundException and Android, but I have yet
I have seen quite a few solutions on this kind of problem (esp. this
I have seen quite a few questions here about the best storage ideologies for

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.