Pomelo.EntityFrameworkCore.MySql icon indicating copy to clipboard operation
Pomelo.EntityFrameworkCore.MySql copied to clipboard

Wrong output from ToQueryString

Open mehrdad-goudarzi opened this issue 1 year ago • 0 comments

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 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) )

MySQL 8.4.0: Operating system: docker image mysql:latest Pomelo.EntityFrameworkCore.MySql version: 8.0.0 Microsoft.AspNetCore.App version: net8.0

mehrdad-goudarzi avatar Jun 10 '24 08:06 mehrdad-goudarzi