- 修复 Enum.ToString() 即使 MapType=int 也应解析成 string;#1252 #806

This commit is contained in:
2881099
2023-06-28 17:44:13 +08:00
parent b164a08747
commit 2a3db8a2c2
28 changed files with 325 additions and 56 deletions

View File

@ -90,7 +90,18 @@ namespace FreeSql.Odbc.Dameng
if (callExp.Method.DeclaringType.IsNumberType()) return "dbms_random.value";
return null;
case "ToString":
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null;
if (callExp.Object != null)
{
if (callExp.Object.Type.NullableTypeOrThis().IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null;
}
return null;
}

View File

@ -90,7 +90,18 @@ namespace FreeSql.Odbc.Default
if (callExp.Method.DeclaringType.IsNumberType()) return _utils.Adapter.LambdaRandom_NextDouble;
return null;
case "ToString":
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? _utils.Adapter.LambdaConvert_ToString(callExp.Object.Type, getExp(callExp.Object)) : null;
if (callExp.Object != null)
{
if (callExp.Object.Type.NullableTypeOrThis().IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? _utils.Adapter.LambdaConvert_ToString(callExp.Object.Type, getExp(callExp.Object)) : null;
}
return null;
}

View File

@ -89,7 +89,18 @@ namespace FreeSql.Odbc.KingbaseES
if (callExp.Method.DeclaringType.IsNumberType()) return "random()";
return null;
case "ToString":
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null;
if (callExp.Object != null)
{
if (callExp.Object.Type.NullableTypeOrThis().IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null;
}
return null;
}

View File

@ -86,7 +86,18 @@ namespace FreeSql.Odbc.MySql
if (callExp.Method.DeclaringType.IsNumberType()) return "rand()";
return null;
case "ToString":
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null;
if (callExp.Object != null)
{
if (callExp.Object.Type.NullableTypeOrThis().IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null;
}
return null;
}

View File

@ -90,7 +90,18 @@ namespace FreeSql.Odbc.Oracle
if (callExp.Method.DeclaringType.IsNumberType()) return "dbms_random.value";
return null;
case "ToString":
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null;
if (callExp.Object != null)
{
if (callExp.Object.Type.NullableTypeOrThis().IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null;
}
return null;
}

View File

@ -89,7 +89,18 @@ namespace FreeSql.Odbc.PostgreSQL
if (callExp.Method.DeclaringType.IsNumberType()) return "random()";
return null;
case "ToString":
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null;
if (callExp.Object != null)
{
if (callExp.Object.Type.NullableTypeOrThis().IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null;
}
return null;
}

View File

@ -93,10 +93,21 @@ namespace FreeSql.Odbc.SqlServer
if (callExp.Method.DeclaringType.IsNumberType()) return "rand()";
return null;
case "ToString":
var gentype2 = callExp.Object.Type.NullableTypeOrThis();
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ?
if (callExp.Object != null)
{
var gentype2 = callExp.Object.Type.NullableTypeOrThis();
if (gentype2.IsEnum)
{
tsc.SetMapColumnTmp(null);
var oldMapType = tsc.SetMapTypeReturnOld(typeof(string));
var enumStr = ExpressionLambdaToSql(callExp.Object, tsc);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
return enumStr;
}
return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ?
$"cast({getExp(callExp.Object)} as varchar(36))" :
$"cast({getExp(callExp.Object)} as nvarchar{(gentype2.IsNumberType() || gentype2.IsEnum ? "(100)" : "(max)")})") : null;
}
return null;
}