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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:52:57+00:00 2026-05-25T16:52:57+00:00

I am trying to use Dynamic Linq (the one published by ScottGu) to do

  • 0

I am trying to use Dynamic Linq (the one published by ScottGu) to do a GroupBy (lambda expression). I have an object. And i am doing AsQueryable. THis is what i have..

var result = Items.AsQueryable().GroupBy("DeliveryDate");

but it gives me an error saying that arguments cannot be inferred from usage. I think its not looking at the right OrderBy.

Items is a List<Stock>.

I tried adding the < > to GroupBy but i think i need to pass more than 1 item. I am a little confused.

The field that i am passing in (via a string) could be any type, in this example it is a DateTime.

If I do my standard LINQ it does work. i.e.:

var result = Items.AsQueryable().GroupBy( x => x.DeliveryDate);

Here is the extension method (from ScottGu):

public static IQueryable GroupBy(this IQueryable source, string keySelector, string elementSelector, params object[] values) {
    if (source == null) throw new ArgumentNullException("source");
    if (keySelector == null) throw new ArgumentNullException("keySelector");
    if (elementSelector == null) throw new ArgumentNullException("elementSelector");
    LambdaExpression keyLambda = DynamicExpression.ParseLambda(source.ElementType, null, keySelector, values);
    LambdaExpression elementLambda = DynamicExpression.ParseLambda(source.ElementType, null, elementSelector, values);
    return source.Provider.CreateQuery(
        Expression.Call(
            typeof(Queryable), "GroupBy",
            new Type[] { source.ElementType, keyLambda.Body.Type, elementLambda.Body.Type },
            source.Expression, Expression.Quote(keyLambda), Expression.Quote(elementLambda)));
}

I have the using in the project using System.Linq.Dynamic; – and i am using dynamic OrderBy in another method, so i know it should be able to see it.

I am a little confused, it seems using dynamic LINQ it doesn’t understand what object I am using.

  • 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-25T16:52:58+00:00Added an answer on May 25, 2026 at 4:52 pm

    The extension method with this signature

    public static IQueryable GroupBy(this IQueryable source, 
            string keySelector, string elementSelector, params object[] values)
    

    isn’t being invoked by this line

    var result =  Items.AsQueryable().GroupBy("DeliveryDate");
    

    as there’s only one non-this argument! So the compiler thinks you’re after the regular GroupBy (that takes a Func) and gets confused.

    You need to supply the other selector string.

    edit to add

    The normal GroupBy has lots of overloads, and so Dynamic Linq needs to offer just as much flexibility. GroupBy produces a sequence of groupings each of which has a key and a sequence of elements. If, as in your conventional LINQ call, no mention is made of the elements, the source objects themselves are used as elements.

    For example, using some hypothetical classes, grouping Orders by OrderDate produces an IEnumerable<IGrouping<DateTime, Order>>.

    But we could say that we only care about the OrderId in the output, so we could give GroupBy an elementSelector to make it produce an IEnumerable<IGrouping<DateTime, int>>.

    To tell Dynamic Linq to use the Item itself as the element, we use the magic string "it" as the elementSelector:

    var result = Items.AsQueryable().GroupBy("DeliveryDate", "it");
    

    This should then have the same effect as the conventional LINQ call

    var result = Items.AsQueryable().GroupBy(i => i.DeliveryDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to use dynamic LINQ to Entity in my application for
I'm trying to use PredicateBuilder to compose dynamic linq queries. In my object, I
How can I use dynamic LINQ in Visual Studio 2008? I'm trying to use
Using LINQ , I've been trying to use the System.Linq.Dynamic library in order to
I'm trying to use dynamic variable names. So inside this loop I want to
Is it possible to use a dynamic Linq Expression inside a Query Expression? Something
I am trying to use a dynamic linq query to retrieve an IEnumerable<T> from
I have this object.. $object = $(.service-box:first).attr(rel) # => spaghetti I am trying to
I am trying to understand dynamic linq as used by Scott Guthrie in this
I've been trying to use a dynamic view in Kohana 3.2 without success. I'm

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.