Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong output from ToQueryString #1926

Open
mehrdad-goudarzi opened this issue Jun 10, 2024 · 0 comments
Open

Wrong output from ToQueryString #1926

mehrdad-goudarzi opened this issue Jun 10, 2024 · 0 comments

Comments

@mehrdad-goudarzi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant