Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Linq.Dynamic.ParseException: 'Operator '>' incompatible with operand types 'DateTime?' and 'Int32''

How can I correctly parse sdate ?

   IQueryable bddata = Junior2KepwareContext.Set(type)
       .Where($"C_NUMERICID == {idLinea}")
       .Where("C_TIMESTAMP > "+ startDate )
       .OrderBy("C_TIMESTAMP");

System.Linq.Dynamic.ParseException: 'Operator '>' incompatible with operand types 'DateTime?' and 'Int32''

enter image description here

enter image description here

like image 520
Massimo Variolo Avatar asked Feb 15 '26 21:02

Massimo Variolo


1 Answers

You need to use parameters:

IQueryable bddata = Junior2KepwareContext.Set(type)
   .Where($"C_NUMERICID == {idLinea}")
   // @0 is first parameter in the list, @1 is second etc
   .Where("C_TIMESTAMP > @0", startDate) // startDate is of type DateTime, not string
   .OrderBy("C_TIMESTAMP");

It's a good practice to always use parameters instead of inlining values (so for example use it for idLinea too).

like image 92
Evk Avatar answered Feb 18 '26 11:02

Evk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!