Works with Oracle.EntityFrameWorkCore beta 2 but broken with beta 3 - OracleRelationalCommand.Create — oracle-tech

    Forum Stats

  • 3,716,003 Users
  • 2,242,928 Discussions
  • 7,845,734 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Works with Oracle.EntityFrameWorkCore beta 2 but broken with beta 3 - OracleRelationalCommand.Create

MikeR_Wake
MikeR_Wake Member Posts: 2 Green Ribbon
edited May 2019 in ODP.NET

For a new application, we are using ASP.NET Core 2.2 Identity with the schema created in Oracle. We let the Oracle provider create a migration for the Identity tables and then generated a script from the migration. It has been working great with the Oracle EF Provider beta 2. However, with beta 3, there is an exception when the Identity framework tries to write a value to the LockoutEnd field. It fails with the error shown below. The datatype for the LockoutEnd field is TIMESTAMP (3) WITH TIME ZONE and the .NET datatype is DateTimeWithOffset. As mentioned, this works fine with the beta 2 release. Since this works in beta 2 I don't want to spend time looking for a work around in case this will work again in a future release.

Here is the mapping that is being used for the LockoutEnd field:

LockoutEnd (Nullable<DateTimeOffset>) 6 6 -1 -1 -1

        Annotations:

          Relational:TypeMapping: Oracle.EntityFrameworkCore.Storage.Internal.OracleDateTimeOffsetTypeMapping

Error during update:

OracleRelationalCommand.CreateCommand() :  System.ArgumentException: Value does not fall within the expected range.

   at Oracle.ManagedDataAccess.Client.OracleParameter.set_Value(Object value)

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

   at Microsoft.EntityFrameworkCore.Storage.Internal.TypeMappedRelationalParameter.AddDbParameter(DbCommand command, Object value)

   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBase.AddDbParameter(DbCommand command, IReadOnlyDictionary`2 parameterValues)

   at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.CreateCommand(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)

ERROR: An exception occurred in the database while saving changes for context type 'Wake.LandRecords.Ptms.Services.Identity.Infrastructure.Data.ApplicationDbContext'.

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.ArgumentException: Value does not fall within the expected range.

   at Oracle.ManagedDataAccess.Client.OracleParameter.set_Value(Object value)

Best Answer

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,753 Employee
    edited April 2019 Accepted Answer

    We plan to fix DateTimeOffset in Beta 4. I don't know if it will solve your specific use case, but be sure to try it out and let us know when we release the next beta.

Answers

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,753 Employee
    edited April 2019

    There are known issues with using with using DateTimeOffset with the Oracle EF Core Beta. These are noted in both the Beta 2 and Beta 3 doc. Oracle is working on resolving these issues by production.

  • MikeR_Wake
    MikeR_Wake Member Posts: 2 Green Ribbon
    edited April 2019

    I see it in the docs now. Thanks!

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,753 Employee
    edited April 2019 Accepted Answer

    We plan to fix DateTimeOffset in Beta 4. I don't know if it will solve your specific use case, but be sure to try it out and let us know when we release the next beta.

  • sanboz
    sanboz Member Posts: 1
    edited May 2019

    I've found a trick in order to solve this issue.

    The idea is to map DateTimeOffset inside HashTable of OracleParameter.

    This trick is not a good practice because it modify a private variable and in future this fix could be not working as expected so use it at your risk.

    I copy a piece of code that describe idea:

    var assembly = typeof(OracleCommand).Assembly;

    var allAssemblyTypes = assembly.GetTypes();

    var oracleDbTypeTableType = allAssemblyTypes.Where(t => t.Name == "OraDb_DbTypeTable").First();

    var hashTableFieldInfo = oracleDbTypeTableType.GetField("s_table", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

    var hashTableOfMappingTypes = (Hashtable)hashTableFieldInfo.GetValue(null);

    hashTableOfMappingTypes.Add(typeof(DateTimeOffset), OracleDbType.TimeStamp);

    Regards,

    Sandro

Sign In or Register to comment.