mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 修复 Enum.ToString() 即使 MapType=int 也应解析成 string;#1252 #806
This commit is contained in:
		@@ -92,10 +92,21 @@ namespace FreeSql.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) ? 
 | 
			
		||||
                                    $"cast({getExp(callExp.Object)} as varchar(36))" : 
 | 
			
		||||
                            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