Page 1 of 1
Invalid SQL is being generated when Enum value used
Posted: Mon 25 May 2020 13:55
by Toshik
Code: Select all
// Since my first post was deleted by some reason, I am posting it once again
Hello. After update to the latest (8.17.1612) Devart Driver (from 8.12.1307) we've got an issue with SQL Query generation when Enum values are being used in LINQ expression.
LINQ:
Code: Select all
var result = dbContext.Set<Record>().Select(x => x.EnumValue ?? SomeEnum.One).ToList();
produces invalid SQL query:
Code: Select all
SELECT COALESCE(r.enum_int_column, One)
FROM records AS r
with an obvious error
Code: Select all
Unknown column 'One' in 'field list'
But, when Enum value is being used as a conditional value - it works fine.
LINQ
Code: Select all
dbContext.Set<Record>().Select(x => x.EnumValue == SomeEnum.One ? true : false).ToList()
generates proper SQL query:
Code: Select all
SELECT (CASE
WHEN r.enum_int_column = 1 THEN 1
ELSE 0
END)
FROM records AS r
Combining both expressions still produces invalid SQL.
LINQ:
Code: Select all
var result = dbContext.Set<Record>().Select(x => x.EnumValue == SomeEnum.Zero ? SomeEnum.One : x.EnumValue).ToList();
produces:
Code: Select all
SELECT (CASE
WHEN r.enum_int_column = 0 THEN One
ELSE r.enum_int_column
END)
FROM records AS r
Here we may see proper SQL for an condition part and invalid one for return value part.
The same SQL erros as an result
Code: Select all
Unknown column 'One' in 'field list'
Git Repo with Test project to reproduce:
https://github.com/Toshik/devart-mysql-bug-enums.git
Re: Invalid SQL is being generated when Enum value used
Posted: Thu 28 May 2020 15:47
by Toshik
Update:
The same issue exists in the PostgreSql driver "Devart.Data.PostgreSql.EFCore" version "7.17.1612"
Are there any news regarding this issue?
Re: Invalid SQL is being generated when Enum value used
Posted: Tue 02 Jun 2020 15:06
by Shalex
Thank you for your report and test project. We have reproduced the issue and are working on the fix.
Re: Invalid SQL is being generated when Enum value used
Posted: Tue 16 Jun 2020 14:41
by Toshik
Shalex wrote: ↑Tue 02 Jun 2020 15:06
Thank you for your report and test project. We have reproduced the issue and are working on the fix.
Any news or an ETA on fix? We are really blocked on that.
Re: Invalid SQL is being generated when Enum value used
Posted: Tue 16 Jun 2020 20:21
by Shalex
The bug with SQL generation in EF Core 3, when enum values are used in CASE and COALESCE statements, is fixed. We are planning to provide the new public build of dotConnect for MySQL in several days.
Re: Invalid SQL is being generated when Enum value used
Posted: Sat 20 Jun 2020 15:41
by Shalex
New build of dotConnect for MySQL 8.17.1666 is available for download:
viewtopic.php?f=2&t=41286.