We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
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.
The text was updated successfully, but these errors were encountered:
Quick question: do you get the same error when using DateTime instead a nullable DateTime ?
DateTime
Sorry, something went wrong.
Yes. It doesn't matter if it is nullable or not.
@striker8118 is this still an issue for you?
Hello @bobbymthompson, I'm not able to reproduce this using the latest version. I'll close this issue.
[Fact] public void Max_Where_On_DateTime() { // Arrange var users = User.GenerateSampleModels(10); // Act var typed = users .Where(u => users.Max(m => m.BirthDate) == u.BirthDate) .ToList(); var dynamic = users.AsQueryable() .Where("@0.Max(BirthDate) == BirthDate", users) .ToList(); // Assert dynamic.Should().BeEquivalentTo(typed); } [Fact] public void Max_Where_On_NullableDateTime() { // Arrange var users = User.GenerateSampleModels(10); // Act var typed = users .Where(u => users.Max(m => m.EndDate) == u.EndDate) .ToList(); var dynamic = users.AsQueryable() .Where("@0.Max(EndDate) == EndDate", users) .ToList(); // Assert dynamic.Should().BeEquivalentTo(typed); }
#744
StefH
No branches or pull requests
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::ParseAggregate
Upon calling into this method it will change the args Type from a Nullable DateTime to an object. Stepping over this bypasses the issue.
The text was updated successfully, but these errors were encountered: