Dynamic LINQ fails with DateTime / timestamp columns
Posted: Tue 07 Nov 2017 19:25
Hi.
I´m using LinqConnect 4.4.727 against Postgres 9.4.
I devised a LINQ Dynamic user´s query facility. It works ok, but when the target property is a DateTime (mapped to timestamp) there is no way the query succeed. Suppose, as an example, the property is called startDate, and the user selects a LessThan operator, with a predicate of 2016-11-05.
The primary contruction ( "startDate < '2016-11-05' ) is rejected by the Dynamic.cs module, because cannot compare a DateTime against a string or (worse) char constant.
The recommended way to go is to use an implied constructor
"startDate < DateTime(2016, 11, 05)"
Using this form, LinqConnect throws an exception, telling some object is not mapped to the table. I suppose the not "mapped object" is the constructor DateTime(...)
My last attempt was to construct a complete expression of the form
"startDate.Year < 2016 || ( startDate.Year == 2016 && startDate.Month < 11 ) || ( startDate.Year == 2016 && startDate.Month == 11 && startDate.Day < 5 )". This time the exception is thrown at Devart.Data.Linq.Engine.j.b.a(SqlExpression A_0, Type A_1), "Object reference not set..."
Could someone help? I´m between two fires: on one side, Dynamic LINQ which cannot understand date constants; on the other, Linq Connect which cannot understand a constructor as a predicate or cannot understand some properties of the DateTime type at runtime.
TIA
I´m using LinqConnect 4.4.727 against Postgres 9.4.
I devised a LINQ Dynamic user´s query facility. It works ok, but when the target property is a DateTime (mapped to timestamp) there is no way the query succeed. Suppose, as an example, the property is called startDate, and the user selects a LessThan operator, with a predicate of 2016-11-05.
The primary contruction ( "startDate < '2016-11-05' ) is rejected by the Dynamic.cs module, because cannot compare a DateTime against a string or (worse) char constant.
The recommended way to go is to use an implied constructor
"startDate < DateTime(2016, 11, 05)"
Using this form, LinqConnect throws an exception, telling some object is not mapped to the table. I suppose the not "mapped object" is the constructor DateTime(...)
My last attempt was to construct a complete expression of the form
"startDate.Year < 2016 || ( startDate.Year == 2016 && startDate.Month < 11 ) || ( startDate.Year == 2016 && startDate.Month == 11 && startDate.Day < 5 )". This time the exception is thrown at Devart.Data.Linq.Engine.j.b.a(SqlExpression A_0, Type A_1), "Object reference not set..."
Could someone help? I´m between two fires: on one side, Dynamic LINQ which cannot understand date constants; on the other, Linq Connect which cannot understand a constructor as a predicate or cannot understand some properties of the DateTime type at runtime.
TIA