Skip to content
New issue

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

Question: DateTime constructor using ticks #439

Closed
zspitz opened this issue Oct 28, 2020 · 1 comment
Closed

Question: DateTime constructor using ticks #439

zspitz opened this issue Oct 28, 2020 · 1 comment
Assignees
Labels

Comments

@zspitz
Copy link

zspitz commented Oct 28, 2020

The following:

public class Person {
    public DateTime DOB { get; set; }
}
var selector = $"DOB > DateTime(633979008000000000)";
var prm = Parameter(typeof(Person));
var parser = new ExpressionParser(new[] { prm }, selector, new object[] { }, ParsingConfig.Default);
var expr = parser.Parse(null);

fails with:

System.Linq.Dynamic.Core.Exceptions.ParseException: 'A value of type 'Int64' cannot be converted to type 'DateTime''

Presumably, because Dynamic LINQ interprets DateTime(...) as a conversion from the long literal value, which isn't found; before searching for the appropriate constructor.

Is this the intended behavior?

I can work around this by passing in DateTimeKind as the second argument to the constructor:

var selector = "DOB > DateTime(633979008000000000, DateTimeKind.Unspecified)";

Is there any other way to force Dynamic LINQ to recognize this as a call to the constructor?

@StefH StefH self-assigned this Oct 31, 2020
@StefH StefH added the bug label Nov 7, 2020
@StefH
Copy link
Collaborator

StefH commented Nov 7, 2020

Solved by #449

@StefH StefH closed this as completed Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants