Expression with enum value not converted correctly to SQL

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
HL00
Posts: 5
Joined: Thu 03 Jun 2021 14:08

Expression with enum value not converted correctly to SQL

Post by HL00 » Thu 03 Jun 2021 15:31

Hi, I'm using the Devart Oracle provider with EF Core 5. I generate a Linq expression in code and execute it using the EntityQueryProvider.

This is the DebugView of the Expression.

Code: Select all

.Call System.Linq.Queryable.First(
    .Extension<Microsoft.EntityFrameworkCore.Query.QueryRootExpression>,
    '(.Lambda #Lambda1<System.Func`2[DB.SomeTable,System.Boolean]>))

.Lambda #Lambda1<System.Func`2[DB.SomeTable,System.Boolean]>(DB.SomeTable $x) {
    (System.Nullable`1[System.Int32]).If ($x.Status == "0") {
        .Constant<System.Nullable`1[DB.StatusEnum]>(EnumVal0)
    } .Else {
        .If ($x.Status == "1") {
            .Constant<System.Nullable`1[DB.StatusEnum]>(EnumVal1)
        } .Else {
            .If ($x.Status == "2") {
                .Constant<System.Nullable`1[DB.StatusEnum]>(EnumVal2)
            } .Else {
                null
            }
        }
    } == (System.Nullable`1[System.Int32]).Constant<DB.StatusEnum>(EnumVal1)
}

This gets translated into a query with the following where statement:

Code: Select all

WHERE CASE
	  WHEN "t".STATUS = N'0' THEN 0
	  WHEN "t".STATUS = N'1' THEN 1
	  WHEN "t".STATUS = N'2' THEN 2
	  ELSE NULL
END = EnumVal1
Which crashes Oracle because it doesn't recognize "EnumVal1". I expected this to get translated since the enum values on the left hand of the expression are converted, but it fails to. Since this functionality did work for us on EF6, I assume it is an issue with Devart (or EF Core?), but if there's any ways of solving/circumventing this from my end I would love to hear.

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

Re: Expression with enum value not converted correctly to SQL

Post by Shalex » Mon 07 Jun 2021 07:54

Could you please send us a small test project with the corresponding DDL/DML script for reproducing the issue?

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

Re: Expression with enum value not converted correctly to SQL

Post by Shalex » Mon 07 Jun 2021 08:04

Make sure that the problem persists with the newest build v9.14.1273.

HL00
Posts: 5
Joined: Thu 03 Jun 2021 14:08

Re: Expression with enum value not converted correctly to SQL

Post by HL00 » Tue 08 Jun 2021 11:49

Yes, the issue still persists in v9.14.1273.

I've send a small test project through the contact form

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

Re: Expression with enum value not converted correctly to SQL

Post by Shalex » Fri 11 Jun 2021 17:59

HL00 wrote: Tue 08 Jun 2021 11:49 Yes, the issue still persists in v9.14.1273.

I've send a small test project through the contact form
Sorry, but we didn't receive your test project. We have just sent the credentials for accessing our FTP server to your email used when registering on the forum.

HL00
Posts: 5
Joined: Thu 03 Jun 2021 14:08

Re: Expression with enum value not converted correctly to SQL

Post by HL00 » Mon 14 Jun 2021 07:37

Ah, I was wondering why the contact form said the request was succesful but I never got a confirmation mail. I've uploaded the files to the FTP server as "EnumOracleCrashDemo.zip"

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

Re: Expression with enum value not converted correctly to SQL

Post by Shalex » Mon 14 Jun 2021 18:19

HL00 wrote: Mon 14 Jun 2021 07:37 Ah, I was wondering why the contact form said the request was succesful but I never got a confirmation mail.
We have initiated an internal investigation to find out the reason why your original ticket was not submitted.
HL00 wrote: Mon 14 Jun 2021 07:37I've uploaded the files to the FTP server as "EnumOracleCrashDemo.zip"
Thank you for the test project. We have reproduced the issue and will notify you when it is fixed.

HL00
Posts: 5
Joined: Thu 03 Jun 2021 14:08

Re: Expression with enum value not converted correctly to SQL

Post by HL00 » Tue 15 Jun 2021 07:34

Shalex wrote: Mon 14 Jun 2021 18:19 We have initiated an internal investigation to find out the reason why your original ticket was not submitted.
If it helps, I was using chrome without addons. In addition, the first time I attempted to submit it, it crashed entirely with some vague error message I don't remember. The second time I didn't do anything different and it seemed to work. I also remember I filled out that I'm a licensed user but did not enter my license number
Shalex wrote: Mon 14 Jun 2021 18:19 Thank you for the test project. We have reproduced the issue and will notify you when it is fixed.
Great to hear, thanks!

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

Re: Expression with enum value not converted correctly to SQL

Post by Shalex » Tue 22 Jun 2021 10:37

The bug with comparing enum values in EF Core 3 and EF Core 5 is fixed. We will notify you when a new public build is available for download.

Post Reply