Invalid SQL is being generated when Enum value used

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Toshik
Posts: 5
Joined: Thu 19 Jul 2018 15:48

Invalid SQL is being generated when Enum value used

Post by Toshik » Mon 25 May 2020 13:55

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

Toshik
Posts: 5
Joined: Thu 19 Jul 2018 15:48

Re: Invalid SQL is being generated when Enum value used

Post by Toshik » Thu 28 May 2020 15:47

Update:
The same issue exists in the PostgreSql driver "Devart.Data.PostgreSql.EFCore" version "7.17.1612"

Are there any news regarding this issue?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Invalid SQL is being generated when Enum value used

Post by Shalex » 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.

Toshik
Posts: 5
Joined: Thu 19 Jul 2018 15:48

Re: Invalid SQL is being generated when Enum value used

Post by Toshik » Tue 16 Jun 2020 14:41

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Invalid SQL is being generated when Enum value used

Post by Shalex » Tue 16 Jun 2020 20:21

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Invalid SQL is being generated when Enum value used

Post by Shalex » Sat 20 Jun 2020 15:41

New build of dotConnect for MySQL 8.17.1666 is available for download: viewtopic.php?f=2&t=41286.

Post Reply