Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

EF Core 3.1 beta - Error casting Enum inside Where Clause

4263965Jun 22 2020 — edited Jun 23 2020

After migrating to Oracle EF Core 3.19.0-beta I'm getting an error when casting an enum inside a Where clause:

private static EmailTemplate GetTemplate(TemplateType templateType)

        {

            return _context.FinancialEmailTemplate

                .Where(t => t.Code == (int)templateType)

                .FirstOrDefault();

        }

The error only happens when the Enum is a parameter of the function. If the where clause is like

.Where(t => t.Code == (int)TemplateType.MultipleBillets)

the query works. Also works fine if I assign the parameter to a local variable.

The StackTrace:

Message:

    System.ArgumentException : Value does not fall within the expected range.

  Stack Trace:

    OracleParameter.set_Value(Object value)

    RelationalTypeMapping.CreateParameter(DbCommand command, String name, Object value, Nullable`1 nullable)

    TypeMappedRelationalParameter.AddDbParameter(DbCommand command, Object value)

    RelationalParameterBase.AddDbParameter(DbCommand command, IReadOnlyDictionary`2 parameterValues)

    OracleRelationalCommand.CreateCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)

    OracleRelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)

    Enumerator.InitializeReader(DbContext _, Boolean result)

    OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)

    Enumerator.MoveNext()

    Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)

    QueryCompiler.Execute[TResult](Expression query)

    EntityQueryProvider.Execute[TResult](Expression expression)

    Queryable.FirstOrDefault[TSource](IQueryable`1 source)

This post has been answered by Alex Keh-Oracle on Jun 23 2020
Jump to Answer
Comments
Post Details
Added on Jun 22 2020
3 comments
737 views