System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

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

Open victorr99 opened this issue 1 month ago • 1 comments

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

victorr99 avatar Dec 03 '25 15:12 victorr99

This line may be the cause? https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/c0e417c014bcffad2326201c5c562431f72d9026/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs#L2207

It does not perform a case insensitive check. Not sure why this isn't an issue with integers.

Anyway, none of Contains(methodName) calls are case insensitive.

If I'm stepping through the code with the debugger and making it enter the branch of the line above (while keeping the name fully uppercase), the code works like expected.

victorr99 avatar Dec 03 '25 16:12 victorr99