Dynamic LINQ fails with DateTime / timestamp columns

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
-marcelo-
Posts: 26
Joined: Wed 28 Jun 2017 12:35

Dynamic LINQ fails with DateTime / timestamp columns

Post by -marcelo- » 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

-marcelo-
Posts: 26
Joined: Wed 28 Jun 2017 12:35

Re: Dynamic LINQ fails with DateTime / timestamp columns

Post by -marcelo- » Wed 08 Nov 2017 16:10

Sorry. It was my guilt.
I´m working with three solutions at a time: my base library (which builds the string expressions for the Dynamic LINQ, among other things), the "DAL" library (the one with the LinqConnect classes) and the application properly.
On some of the updates to the first one, surely I did not rebuild the others, so, even if I found the trick, it was not reflected. In short, to be useful for other users, to pass a DateTime predicate to Dynamic LINQ library, it must be of the form
" DateTime( year, month, day ) "; in my example, the complete expression result in
"startDate < DateTime( 2016, 8, 11 )".
It works like a charm.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Dynamic LINQ fails with DateTime / timestamp columns

Post by Shalex » Fri 10 Nov 2017 16:20

Thank you for letting us know.

Post Reply