mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 修复 Enum.ToString() 即使 MapType=int 也应解析成 string;#1252 #806
This commit is contained in:
@ -90,7 +90,18 @@ namespace FreeSql.Custom
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,18 @@ namespace FreeSql.Custom.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;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,18 @@ namespace FreeSql.Custom.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;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,18 @@ namespace FreeSql.Custom.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;
|
||||
}
|
||||
|
||||
|
@ -93,10 +93,21 @@ namespace FreeSql.Custom.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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user