mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
SqlServer support for xml path
This commit is contained in:
parent
111deccb8a
commit
8875d74111
@ -561,5 +561,9 @@ namespace SqlSugar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public virtual string GetForXmlPath()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,5 +88,6 @@ namespace SqlSugar
|
||||
string Desc(MethodCallExpressionModel model);
|
||||
string Stuff(MethodCallExpressionModel model);
|
||||
string GetDateString(string dateValue,string format);
|
||||
string GetForXmlPath();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace SqlSugar
|
||||
private ExpressionContext context = null;
|
||||
private string subKey = "$SubAs:";
|
||||
private bool hasWhere;
|
||||
private bool isXmlPath = false;
|
||||
public SubResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
|
||||
{
|
||||
this.context = context;
|
||||
@ -124,6 +125,14 @@ namespace SqlSugar
|
||||
{
|
||||
sql = string.Join(UtilConstants.Space, sqlItems);
|
||||
}
|
||||
if (isXmlPath)
|
||||
{
|
||||
var xmlPath = context.DbMehtods.GetForXmlPath();
|
||||
if (xmlPath.HasValue())
|
||||
{
|
||||
sql = sql + xmlPath;
|
||||
}
|
||||
}
|
||||
return this.context.DbMehtods.Pack(sql);
|
||||
}
|
||||
|
||||
@ -185,6 +194,10 @@ namespace SqlSugar
|
||||
{
|
||||
item = items.First(s => s is SubAndIF);
|
||||
}
|
||||
else if (item is SubSelectStringJoin)
|
||||
{
|
||||
isXmlPath = true;
|
||||
}
|
||||
|
||||
item.Context = this.context;
|
||||
item.Expression = exp;
|
||||
|
@ -20,6 +20,14 @@ namespace SqlSugar
|
||||
}
|
||||
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
|
||||
{
|
||||
public override string GetForXmlPath()
|
||||
{
|
||||
return " FOR XML PATH('')),1,len(N','),'') ";
|
||||
}
|
||||
public override string GetStringJoinSelector(string result, string separator)
|
||||
{
|
||||
return $"stuff((SELECT cast(N'{separator}' as nvarchar(max)) + cast({result} as nvarchar(max))";
|
||||
}
|
||||
public override string DateValue(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
|
Loading…
Reference in New Issue
Block a user