DelegateDecompiler: Can't get DelegateDecompiler to play with DateTime
I absolutely love the concept, but I can’t get it to work with comparing DateTimes, something that I need to do a lot.
I’ve tried
[Computed]
public bool IsOverdue
{
return this.FinishedAt.HasValue && this.FinishedAt.Value < DateTime.Now.AddDays(-1);
}
but it throws
LINQ to Entities does not recognize the method ‘System.DateTime AddDays(Double)’ method, and this method cannot be translated into a store expression.
I’ve tried using DbFunctions:
[Computed]
public bool IsOverdue
{
return this.FinishedAt.HasValue && this.FinishedAt.Value < DbFunctions.AddDays(DateTime.Now, -1)
}
But it throws
Unable to cast object of type ‘System.Reflection.RuntimeConstructorInfo’ to type ‘System.Reflection.MethodInfo’.
Is there any way I can get a property like this to work, or am I out of luck?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (8 by maintainers)
Commits related to this issue
- Add tests for #85 — committed to hazzik/DelegateDecompiler by hazzik 8 years ago
- Fixes #72, #82, #85 * Improve Nullable`1 folding * VB compiler generates `Decimal.Compare(x,y) cgt.un 0` for not equal * Compiler may generate cgt.un for not null checks * Compiler may generate `call... — committed to hazzik/DelegateDecompiler by hazzik 8 years ago
Pushed to NuGet
Fixed in 9e114ff
If you can’t get it to work, can you create a demo project to demonstrate the issue?
Hi @Heras
This will not work as the variable will be inlined into the expression.
This works in the following way:
or
The
.Value/cast is required because the DelegateDecompiler does not yet support optimizing folding of nullable value in this case.I’m at v.0.19.0 already, but I did notice I have some nuget packages that have updates. I’ll try again when I have every package up-to-date