Page 1 of 1

SQL Server command trying to use float(0,0)

Posted: Fri 31 Jul 2020 19:21
by michaeltmg
I'm evaluating LinqConnect for my company to use in moving an old project to .net core. I'm getting an error on this query

from u in db.user
where u.Created.Value.AddHours(-4) > date.Date
select u.ID

The error is "Line 3: Length or precision specification 0 is invalid."

I ran SQL Server Profiler to capture the SQL being run. It's

exec sp_executesql N'SELECT [t1].[ID]
FROM dbo.[user] [t1]
WHERE DATEADD(ms, (CAST(CONVERT(Float(0,0),@p0 * 3600000) AS Int)) % 86400000, DATEADD(day, (CAST(CONVERT(Float(0,0),@p0 * 3600000) AS Int)) / 86400000, [t1].[Created])) > @p1',N'@p0 float,@p1 datetime',@p0=-4,@p1='2020-07-31 18:18:50.047'

Float(0,0) isn't valid SQL Server syntax, so that's causing the above error. Is this expected behavior, a known error, or is something configured wrong?

Re: SQL Server command trying to use float(0,0)

Posted: Fri 31 Jul 2020 20:44
by michaeltmg
Relatedly, a query of the form

db.User.Where(u => u.Created.Value - TimeSpan.FromDays(1)> date)

returns the error

Failed to convert parameter value from a TimeSpan to a DateTimeOffset.

It works under Linq to SQL

Re: SQL Server command trying to use float(0,0)

Posted: Thu 06 Aug 2020 16:23
by Shalex
Thank you for your report. We have reproduced both issues and are investigating them. We will notify you about the result.

Re: SQL Server command trying to use float(0,0)

Posted: Tue 18 Aug 2020 20:52
by michaeltmg
Just curious if there is any update on this, or if you could tell me where there might be one.

Re: SQL Server command trying to use float(0,0)

Posted: Tue 08 Sep 2020 09:58
by Shalex
* The bug with SQL generation of the explicit cast to FLOAT is fixed
* The bug with subtracting a TimeSpan value from the DATETIME column is fixed

We will notify you when the new public build of LinqConnect is available for download.

Re: SQL Server command trying to use float(0,0)

Posted: Mon 21 Sep 2020 15:11
by Shalex
New build of LinqConnect 4.9.2067 is available for download now: viewtopic.php?f=31&t=42245.