EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Eric_08
Posts: 19
Joined: Wed 11 Jul 2018 21:50

EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Eric_08 » Mon 30 Dec 2019 16:17

Right after upgrading to .NET Core 3.1 and EF Core 3.1 with DevArt 9.10, I started getting ORA-00904 invalid identifier code.

Assume the following:

Code: Select all

public enum ColorType
{
    Red = 0,
    Blue = 1
}

public class SomeObject
{
    public int Id {get; set;}
    public ColorType? Color {get; set;} 
}
The above is a simple object with ColorType being nullable property. Assume that SomeObject is mapped to a table and the following EF Core query:

Code: Select all

 var query = await table1.AsNoTracking()
                    .Where(t => t.ColorType == ColorType.Blue).Select(h => h.Id).ToListAsync();
With the above code, I would get ORA-00904: "BLUE": invalid identifier with the following produced SQL:

Code: Select all

SELECT "g".ID
FROM <some_table> "g"
WHERE "g".Color = Blue
Notice that instead of using integers, the SQL query uses string literal of the enum, which of course is wrong. Strangely, I had used enum in other cases, and it worked correctly. The only difference was the nullable part, which in this case affects how the SQL is generated. Only happens in NET Core 3.1/EF Core 3.1. Works correctly in .NET Core 2.2/EF Core 2.4

Eric_08
Posts: 19
Joined: Wed 11 Jul 2018 21:50

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Eric_08 » Mon 06 Jan 2020 19:26

Any update on this?

kakone
Posts: 12
Joined: Thu 09 Jan 2020 17:30

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by kakone » Thu 09 Jan 2020 17:44

I'm trying dotConnect for Oracle with EF Core 3.1 and I'm also stuck with this bug.
I also noticed that there is the same bug with non nullable enum and .Contains method.
This code :

Code: Select all

var settingsIds = new ApplicationSettingId[] { ApplicationSettingId.SmtpHost, ApplicationSettingId.SmtpPort };
var applicationSettings = dbContext.ApplicationSettings.Where(s => settingsIds.Contains(s.Id)).Select(s => s.TextValue);
produces the SQL

Code: Select all

SELECT "a".TEXT_VALUE
FROM APPLICATION_CONFIGURATION "a"
WHERE "a".ID IN (SmtpHost, SmtpPort)

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Thu 09 Jan 2020 19:56

We have reproduced the bug and will notify you when it is fixed.

Eric_08
Posts: 19
Joined: Wed 11 Jul 2018 21:50

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Eric_08 » Wed 15 Jan 2020 15:14

When can we expect the new build?

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Thu 16 Jan 2020 17:48

The bug with using nullable enum properties with default mapping to integers in .Where() conditions in EF Core 3.1 is fixed.

The internal build with the fix is available at https://download.devart.com/nuget_oracle_9_10_925.zip.

Sv01a
Posts: 7
Joined: Mon 12 Jan 2015 13:01

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Sv01a » Tue 21 Jan 2020 15:05

Same with Select:

Code: Select all

_context.Templates
	 .Select(p => new TemplateDto
		{
 			Id = p.Id,
 			Type = TemplateType.Template// <- Enum
 		})
	 .FirstOrDefaultAsync(cancellationToken);
Sql:

Code: Select all

SELECT :p__template_Id_0 Id, Template Type
      FROM Templates t
      WHERE t.Id = :p__template_Id_0
      FETCH FIRST 1 ROWS ONLY

Devart.Data.Oracle.EFCore="9.10.925"

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Thu 23 Jan 2020 18:00

Thank you for your report. We are investigating the case.

Sv01a
Posts: 7
Joined: Mon 12 Jan 2015 13:01

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Sv01a » Thu 30 Jan 2020 15:09

Any updates?

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Fri 31 Jan 2020 16:50

The bug with using nullable enum properties with default mapping to integers in .Select() clause in EF Core 3.1 is fixed: https://download.devart.com/nuget_oracle_9_10_935.zip.

Sv01a
Posts: 7
Joined: Mon 12 Jan 2015 13:01

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Sv01a » Sat 01 Feb 2020 09:19

unfortunately, i found another case:

Code: Select all

s.Type == Enum1.Val1 ? Enum2.Val1 :
    s.Type == Enum1.Val2 ? Enum2.Val2 :
    Enum2.Val3

Code: Select all

SELECT CASE
    WHEN k0.Type = 3 THEN Val1 
    ELSE CASE
        WHEN k0.Type = 2 THEN Val2 
        ELSE Val3
    END
END c

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Thu 06 Feb 2020 10:51

The bug with generating a subselect within the CASE clause in EF Core 3 is fixed. We will provide the build with the fix in several days.

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Sat 15 Feb 2020 14:46

Please download the internal build from https://download.devart.com/nuget_oracle_9_11_948.zip.

Eric_08
Posts: 19
Joined: Wed 11 Jul 2018 21:50

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Eric_08 » Sat 15 Feb 2020 17:58

Just got the internal build, and so far, so good. Case statement issue also appears to be fixed, which is great. One minor thing I'm seeing is extra dependencies in the Devart.Data.Oracle package. It's now trying to include Microsoft.Windows.Compatibility package that includes all kinds of DLLs that previous package version didn't include. I hope it won't be included in the official version. Other than that, it looks good.

Thanks,
Eric

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

Re: EF Core 3.1 with nullable enum produces ORA-00904 invalid identifier code

Post by Shalex » Mon 17 Feb 2020 12:08

One minor thing I'm seeing is extra dependencies in the Devart.Data.Oracle package. It's now trying to include Microsoft.Windows.Compatibility package that includes all kinds of DLLs that previous package version didn't include. I hope it won't be included in the official version.
We will investigate the question and notify you about the result.

Post Reply