dotnet-db-samples icon indicating copy to clipboard operation
dotnet-db-samples copied to clipboard

Oracle.EntityFrameworkCore not supported converters for System.Guid type

Open elmanav opened this issue 4 years ago • 3 comments

I use strongly-typed entity identifiers of type System.Guid (for example):

public class OrderIdValueConverter : ValueConverter<OrderId, Guid>
{
    public OrderIdValueConverter(ConverterMappingHints mappingHints = null)
        : base(
            id => id.Value,
            value => new OrderId(value),
            mappingHints
        ) { }
}

I expect the converter to be called both ways, but it doesn't. After looking at the parameter creation code on Oracle.EntityFrameworkCore.Storage.Internal.OracleGuidTypeMapping.CreateParameter() I found that the base call Converter.ConvertToProvider(value) is simply omitted (:(. Now code like this:

public override DbParameter CreateParameter(
      [NotNull] DbCommand command,
      [NotNull] string name,
      [CanBeNull] object value,
      bool? nullable = null)
    {
      Check.NotNull<DbCommand>(command, nameof (command));
      OracleParameter oracleParameter = new OracleParameter(name, OracleDbType.Raw, (object) 16, ParameterDirection.Input);
      oracleParameter.Value = value;
      return (DbParameter) oracleParameter;
    }

elmanav avatar Jun 16 '21 10:06 elmanav

I had a similar situation, it seems to only be happening for Guids, I think because they are also translated to Raw. Worked around bit by writing ValueConverter that goes to byte[] instead of Guid.

SierraNL avatar Jun 17 '21 08:06 SierraNL

I had a similar situation, it seems to only be happening for Guids, I think because they are also translated to Raw. Worked around bit by writing ValueConverter that goes to byte[] instead of Guid.

Yes exactly. Only with Guid such a problem. All other mappings of primitive types from Oracle.EntityFrameworkCore.Storage.Internal call the converter. Very sad.

elmanav avatar Jun 17 '21 10:06 elmanav

The Oracle EF Core dev team is reviewing this issue. I'll provide an update when they've concluded on a plan of action.

alexkeh avatar Aug 17 '21 17:08 alexkeh

This is bug 35984370

alexkeh avatar Nov 06 '23 20:11 alexkeh

This bug was fixed for Oracle EF Core 5 and 6 patch releases made starting in early 2022.

alexkeh avatar Nov 15 '23 16:11 alexkeh