You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The returned value of ToQueryString is not exactly what is going to be executed on database.
Try to retrieve rows via EF in C# like bellow:
TimeSpan t = TimeSpan.FromHours(10); var query = context.table1.Where(x => x.Status == 3 && x.CreatedAt < DateTime.Now - t); var sql = query.ToQueryString();
and the sql variable will hold following value:
`SET @__t_0 = TIME '10:00:00.000000';
SELECT t.Id, t.CreatedAt, t.Status
FROM table1 AS t
WHERE (t.Status = 3) AND (t.CreatedAt < (CURRENT_TIMESTAMP() - @__t_0));`
but following query is the one that is getting executed at the end:
'SELECT t.TicketId, t.CreatedAt, t.Status
FROM table1 AS t
WHERE (t.Status = 3) AND (t.CreatedAt < (CURRENT_TIMESTAMP() - time '10:00:00.000000'));'
Further technical details
table1 has following definition: CREATE TABLE table1( id int NOT NULL, createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status tinyint NOT NULL DEFAULT 1 COMMENT 'Default=Open', PRIMARY KEY (id) )
Steps to reproduce
Create a table with a timestamp column:
The issue
The returned value of ToQueryString is not exactly what is going to be executed on database.
Try to retrieve rows via EF in C# like bellow:
TimeSpan t = TimeSpan.FromHours(10); var query = context.table1.Where(x => x.Status == 3 && x.CreatedAt < DateTime.Now - t); var sql = query.ToQueryString();
and the sql variable will hold following value:
`SET @__t_0 = TIME '10:00:00.000000';
SELECT
t
.Id
,t
.CreatedAt
,t
.Status
FROM
table1
ASt
WHERE (
t
.Status
= 3) AND (t
.CreatedAt
< (CURRENT_TIMESTAMP() - @__t_0));`but following query is the one that is getting executed at the end:
'SELECT
t
.TicketId
,t
.CreatedAt
,t
.Status
FROM
table1
ASt
WHERE (
t
.Status
= 3) AND (t
.CreatedAt
< (CURRENT_TIMESTAMP() - time '10:00:00.000000'));'Further technical details
table1 has following definition:
CREATE TABLE table1( id int NOT NULL, createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status tinyint NOT NULL DEFAULT 1 COMMENT 'Default=Open', PRIMARY KEY (id) )
MySQL 8.4.0:
Operating system: docker image mysql:latest
Pomelo.EntityFrameworkCore.MySql version: 8.0.0
Microsoft.AspNetCore.App version: net8.0
The text was updated successfully, but these errors were encountered: