Using this test code:
NetStandardDbContext context = new NetStandardDbContext();
var typed = context.Issues
.Where(i => context.Issues.Max(x => x.RevisionDate) == i.RevisionDate)
.Select(i => new { i.Title, i.RevisionDate })
.ToList();
var success = context.Issues
.Where("@0.Max(RevisionDate) == object(RevisionDate)", context.Issues)
.Select("new(Title, RevisionDate)")
.ToDynamicList();
var failure = context.Issues
.Where("@0.Max(RevisionDate) == RevisionDate", context.Issues)
.Select("new(Title, RevisionDate)")
.ToDynamicList();
Which generates:
select title, revisiondate from issues i where (select max(revisiondate) from issues) = i.revisiondate
Using Max as a dynamic where clause, the following exception occurs:
System.Linq.Dynamic.Core.Exceptions.ParseException: 'Operator '==' incompatible with operand types 'Object' and 'DateTime?''
If you cast the right expression to object, the comparison succeeds. I do not believe that the left expression should be cast to object.
I traced this to ExpressionParser::ParseAggregate
Type callType = typeof(Enumerable);
if (isQueryable && MethodFinder.ContainsMethod(typeof(IQueryableSignatures), methodName, false, args))
{
callType = typeof(Queryable);
}
Upon calling into this method it will change the args Type from a Nullable DateTime to an object. Stepping over this bypasses the issue.
Using this test code:
Which generates:
Using Max as a dynamic where clause, the following exception occurs:
System.Linq.Dynamic.Core.Exceptions.ParseException: 'Operator '==' incompatible with operand types 'Object' and 'DateTime?''
If you cast the right expression to object, the comparison succeeds. I do not believe that the left expression should be cast to object.
I traced this to
ExpressionParser::ParseAggregateUpon calling into this method it will change the args Type from a Nullable DateTime to an object. Stepping over this bypasses the issue.