mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
SqlServer support for xml path
This commit is contained in:
@@ -561,5 +561,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public virtual string GetForXmlPath()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,5 +88,6 @@ namespace SqlSugar
|
|||||||
string Desc(MethodCallExpressionModel model);
|
string Desc(MethodCallExpressionModel model);
|
||||||
string Stuff(MethodCallExpressionModel model);
|
string Stuff(MethodCallExpressionModel model);
|
||||||
string GetDateString(string dateValue,string format);
|
string GetDateString(string dateValue,string format);
|
||||||
|
string GetForXmlPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace SqlSugar
|
|||||||
private ExpressionContext context = null;
|
private ExpressionContext context = null;
|
||||||
private string subKey = "$SubAs:";
|
private string subKey = "$SubAs:";
|
||||||
private bool hasWhere;
|
private bool hasWhere;
|
||||||
|
private bool isXmlPath = false;
|
||||||
public SubResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
|
public SubResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -124,6 +125,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
sql = string.Join(UtilConstants.Space, sqlItems);
|
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);
|
return this.context.DbMehtods.Pack(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +194,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
item = items.First(s => s is SubAndIF);
|
item = items.First(s => s is SubAndIF);
|
||||||
}
|
}
|
||||||
|
else if (item is SubSelectStringJoin)
|
||||||
|
{
|
||||||
|
isXmlPath = true;
|
||||||
|
}
|
||||||
|
|
||||||
item.Context = this.context;
|
item.Context = this.context;
|
||||||
item.Expression = exp;
|
item.Expression = exp;
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
|
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)
|
public override string DateValue(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user