mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 lambda 表达式树解析子查询 ToList + string.Join() 产生 类似 group_concat 的效果(适配了 sqlserver/pgsql/oracle/mysql/sqlite/达梦/金仓) #405;
This commit is contained in:
@ -284,6 +284,24 @@ namespace FreeSql.Odbc.SqlServer
|
||||
return $"'+{_common.IsNull($"cast({ExpressionLambdaToSql(a, tsc)} as nvarchar(max))", "''")}+{nchar}'";
|
||||
}).ToArray();
|
||||
return string.Format(expArgs0, expArgs);
|
||||
case "Join":
|
||||
if (exp.IsStringJoin(out var tolistObjectExp, out var toListMethod, out var toListArgs1))
|
||||
{
|
||||
var newToListArgs0 = Expression.Call(tolistObjectExp, toListMethod,
|
||||
Expression.Lambda(
|
||||
Expression.Call(
|
||||
typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }),
|
||||
Expression.Convert(exp.Arguments[0], typeof(object)),
|
||||
Expression.Convert(toListArgs1.Body, typeof(object))),
|
||||
toListArgs1.Parameters));
|
||||
var newToListSql = getExp(newToListArgs0);
|
||||
if (string.IsNullOrEmpty(newToListSql) == false && newToListSql.StartsWith("(") && newToListSql.EndsWith(")"))
|
||||
{
|
||||
newToListSql = $"stuff({newToListSql.Substring(0, newToListSql.Length - 1)} FOR XML PATH('')),1,len({getExp(exp.Arguments[0])}),'')";
|
||||
return newToListSql;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user