mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 优化 子查询 sum/min/max/avg 默认加 isnull 防止为 NULL 情况;
This commit is contained in:
@ -1264,7 +1264,7 @@ namespace FreeSql.Internal
|
||||
|
||||
var sql4 = fsqlType.GetMethod("ToSql", new Type[] { typeof(string) })?.Invoke(fsql, new object[] { $"{exp3.Method.Name.ToLower()}({fieldSql})" })?.ToString();
|
||||
asSelectBefores.Clear();
|
||||
return $"({sql4.Replace(" \r\n", " \r\n ")})";
|
||||
return _common.IsNull($"({sql4.Replace(" \r\n", " \r\n ")})", 0);
|
||||
}
|
||||
|
||||
var sql3 = manySubSelectAggMethod.Invoke(fsql, new object[] { exp3Args0, FieldAliasOptions.AsProperty }) as string;
|
||||
@ -1319,7 +1319,7 @@ namespace FreeSql.Internal
|
||||
exp3Args0 = new ReplaceHzyTupleToMultiParam().Modify(exp3Args0, fsqltables);
|
||||
var sqlSum = fsqlType.GetMethod("ToSql", new Type[] { typeof(string) })?.Invoke(fsql, new object[] { $"{exp3.Method.Name.ToLower()}({ExpressionLambdaToSql(exp3Args0, tscClone1)})" })?.ToString();
|
||||
if (string.IsNullOrEmpty(sqlSum) == false)
|
||||
return $"({sqlSum.Replace(" \r\n", " \r\n ")})";
|
||||
return _common.IsNull($"({sqlSum.Replace(" \r\n", " \r\n ")})", 0);
|
||||
break;
|
||||
case "ToList":
|
||||
case "ToOne":
|
||||
@ -2124,7 +2124,7 @@ namespace FreeSql.Internal
|
||||
commonExp.ReadAnonymousField(select._tables, field, map, ref index, callExp.Arguments[1], null, null, null, null, false);
|
||||
var fieldSql = field.Length > 0 ? field.Remove(0, 2).ToString() : null;
|
||||
|
||||
e.Result = $"({select.ToSql($"{aggregateMethodName}({fieldSql})").Replace(" \r\n", " \r\n ")})";
|
||||
e.Result = commonExp._common.IsNull($"({select.ToSql($"{aggregateMethodName}({fieldSql})").Replace(" \r\n", " \r\n ")})", 0);
|
||||
return;
|
||||
}
|
||||
throw throwCallExp($"不支持 {callExp.Arguments.Count}个参数的方法");
|
||||
|
Reference in New Issue
Block a user