Skip to content

LINQ methods like Min, Max and Sum remain case sensitive when working with DateTime #967

Description

@victorr99

We observed the strange behavior that the LINQ methods like Min, Max and Sum remain case sensitive when working with DateTime properties. When working with integers for example, thay are indeed case insensitive. We have the option IsCaseSensitive set to false.

Code to reproduce:

 var models = new Model[]
 {
     new Model { Date = new DateTime(2025, 12, 10, 12, 0, 0) },
     new Model { Date = new DateTime(2025, 8, 10, 12, 0, 0) }
 };

 var parameter = Expression.Parameter(typeof(Model[]), "models");

 var parser = new ExpressionParser(
     [parameter],
     "models.MIN(x => x.Date)", // or min, MAX, max
     [],
     new ParsingConfig
     {
          IsCaseSensitive = false
     });

 var expression = parser.Parse(typeof(DateTime));
 var labmda = Expression.Lambda<Func<Model[], DateTime>>(expression, parameter);
 var method = labmda.Compile();

 var result = method(models);
 Console.Write(result);

public class Model
{
    public DateTime Date { get; set; }
}

Exception:

Unhandled exception. System.InvalidOperationException: No generic method 'MIN' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
   at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
   at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.TryParseEnumerable(Expression instance, Type enumerableType, String methodName, Type type, Expression[]& args, Expression& expression)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression, String id)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)

Libary version: 1.7.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions