Skip to content

Commit

Permalink
Reduce the scope of the changes to dotnet#20604 specifically
Browse files Browse the repository at this point in the history
  • Loading branch information
Danevandy99 committed Apr 29, 2024
1 parent 0a70cc4 commit 150d5af
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Storage/RelationalTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public virtual string GenerateSqlLiteral(object? value)
{
value = NormalizeEnumValue(value);

if (Converter != null && Converter.ProviderClrType.UnwrapNullableType() != value?.GetType())
if (Converter != null)
{
value = Converter.ConvertToProvider(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,7 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact

if (instance.Type.IsEnum)
{
if (instance.TypeMapping?.DbType == DbType.String
|| string.Equals(instance.TypeMapping?.StoreTypeNameBase, "VARCHAR", StringComparison.OrdinalIgnoreCase))
{
return instance;
}
else
{
var cases = Enum.GetValues(instance.Type)
.Cast<object>()
.Select(value => new CaseWhenClause(
_sqlExpressionFactory.Equal(instance, _sqlExpressionFactory.Constant(value)),
_sqlExpressionFactory.Constant(value?.ToString(), typeof(string))))
.ToArray();

return _sqlExpressionFactory.Case(cases, _sqlExpressionFactory.Constant(string.Empty, typeof(string)));
}
return _sqlExpressionFactory.Convert(instance, typeof(string));
}

return TypeMapping.TryGetValue(instance.Type, out var storeType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,7 @@ public SqliteObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory
_sqlExpressionFactory.Constant(true.ToString()));
}

if (instance.Type.IsEnum)
{
if (instance.TypeMapping?.DbType == DbType.String
|| string.Equals(instance.TypeMapping?.StoreType, "TEXT", StringComparison.OrdinalIgnoreCase))
{
return instance;
}
else
{
var cases = Enum.GetValues(instance.Type)
.Cast<object>()
.Select(value => new CaseWhenClause(
_sqlExpressionFactory.Equal(instance, _sqlExpressionFactory.Constant(value)),
_sqlExpressionFactory.Constant(value?.ToString(), typeof(string))))
.ToArray();

return _sqlExpressionFactory.Case(cases, _sqlExpressionFactory.Constant(string.Empty, typeof(string)));
}
}

return TypeMapping.Contains(instance.Type)
return TypeMapping.Contains(instance.Type) || instance.Type.IsEnum
? _sqlExpressionFactory.Convert(instance, typeof(string))
: null;
}
Expand Down

0 comments on commit 150d5af

Please sign in to comment.