I am using .NETCore and EF Core in my project. I am unable to query items with expressions using DateTimes.
return _context.table
.Where( x=> x.CPULoad > 90 && X.Date >= DateTime.Now.AddMinutes(-5));
The CPULoad works perfect but the datetime comparions outputs the below.
The LINQ expression '(([x].Date >= DateTime.Now.AddMinutes(-5))' could not be translated and will be evaluated locally.
Can someone explain what i'm doing wrong? Thanks in advance!
try this...
var compareDate = DateTime.Now.AddMinutes(-5);
return _context.table
.Where( x=> x.CPULoad > 90 && X.Date >= compareDate);
essentially the problem here is entity framework does not know how to convert DateTime.Now.AddMinutes(-5)
to SQL, so you need to get the value and then pass that to entity framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With