dotnet-db-samples
dotnet-db-samples copied to clipboard
Oracle.EntityFrameworkCore not supported converters for System.Guid type
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;
}
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.
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.
The Oracle EF Core dev team is reviewing this issue. I'll provide an update when they've concluded on a plan of action.
This is bug 35984370
This bug was fixed for Oracle EF Core 5 and 6 patch releases made starting in early 2022.