mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-08 14:47:59 +08:00
Update .net core project
This commit is contained in:
parent
6c525a5abf
commit
01e7f52196
@ -222,6 +222,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string GetStringJoinSelector(string result, string separator)
|
||||||
|
{
|
||||||
|
return $"string_agg(({result})::text,'{separator}') ";
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string ToInt32(MethodCallExpressionModel model)
|
public virtual string ToInt32(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
@ -556,5 +561,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public virtual string GetForXmlPath()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ namespace SqlSugar
|
|||||||
string StartsWith(MethodCallExpressionModel model);
|
string StartsWith(MethodCallExpressionModel model);
|
||||||
string EndsWith(MethodCallExpressionModel model);
|
string EndsWith(MethodCallExpressionModel model);
|
||||||
string ToInt32(MethodCallExpressionModel model);
|
string ToInt32(MethodCallExpressionModel model);
|
||||||
|
string GetStringJoinSelector(string result,string separator);
|
||||||
string ToInt64(MethodCallExpressionModel model);
|
string ToInt64(MethodCallExpressionModel model);
|
||||||
string ToString(MethodCallExpressionModel model);
|
string ToString(MethodCallExpressionModel model);
|
||||||
string ToVarchar(MethodCallExpressionModel model);
|
string ToVarchar(MethodCallExpressionModel model);
|
||||||
@ -87,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubSelectStringJoin : ISubOperation
|
||||||
|
{
|
||||||
|
public bool HasWhere
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "SelectStringJoin";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression = null)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
var entityType = (exp.Arguments[0] as LambdaExpression).Parameters[0].Type;
|
||||||
|
if (this.Context.InitMappingInfo != null)
|
||||||
|
{
|
||||||
|
this.Context.InitMappingInfo(entityType);
|
||||||
|
this.Context.RefreshMapping();
|
||||||
|
}
|
||||||
|
var result = "";
|
||||||
|
if (this.Context.JoinIndex == 0)
|
||||||
|
result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle);
|
||||||
|
else
|
||||||
|
result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldMultiple);
|
||||||
|
|
||||||
|
SetShortName(exp, result);
|
||||||
|
|
||||||
|
result = this.Context.DbMehtods.GetStringJoinSelector(result, ExpressionTool.GetExpressionValue(exp.Arguments[1]) + "");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetShortName(MethodCallExpression exp, string result)
|
||||||
|
{
|
||||||
|
if (exp.Arguments[0] is LambdaExpression && result.IsContainsIn("+", "-", "*", "/"))
|
||||||
|
{
|
||||||
|
var parameters = (exp.Arguments[0] as LambdaExpression).Parameters;
|
||||||
|
if (parameters != null && parameters.Count > 0)
|
||||||
|
{
|
||||||
|
this.Context.CurrentShortName = this.Context.GetTranslationColumnName(parameters[0].ObjToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetShortNameNext(MethodCallExpression exp, string result)
|
||||||
|
{
|
||||||
|
if (exp.Arguments.Count > 1 && exp.Arguments[1] is LambdaExpression && result.IsContainsIn("+", "-", "*", "/"))
|
||||||
|
{
|
||||||
|
var parameters = (exp.Arguments[1] as LambdaExpression).Parameters;
|
||||||
|
if (parameters != null && parameters.Count > 0)
|
||||||
|
{
|
||||||
|
this.Context.CurrentShortName = this.Context.GetTranslationColumnName(parameters[0].ObjToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
@ -35,7 +35,8 @@ namespace SqlSugar
|
|||||||
new SubAs(){Context=Context},
|
new SubAs(){Context=Context},
|
||||||
new SubHaving(){ Context=Context},
|
new SubHaving(){ Context=Context},
|
||||||
new SubWithNolock(){ Context=Context },
|
new SubWithNolock(){ Context=Context },
|
||||||
new SubEnableTableFilter(){ Context=Context }
|
new SubEnableTableFilter(){ Context=Context },
|
||||||
|
new SubSelectStringJoin{ Context=Context }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,11 @@ namespace SqlSugar
|
|||||||
return default(string);
|
return default(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string SelectStringJoin(Func<T, string> expression,string separator)
|
||||||
|
{
|
||||||
|
return default(string);
|
||||||
|
}
|
||||||
|
|
||||||
public TResult Max<TResult>(Func<T, TResult> expression) where TResult : struct
|
public TResult Max<TResult>(Func<T, TResult> expression) where TResult : struct
|
||||||
{
|
{
|
||||||
return default(TResult);
|
return default(TResult);
|
||||||
|
@ -14,6 +14,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public class MySqlMethod : DefaultDbMethod, IDbMethods
|
public class MySqlMethod : DefaultDbMethod, IDbMethods
|
||||||
{
|
{
|
||||||
|
public override string GetStringJoinSelector(string result, string separator)
|
||||||
|
{
|
||||||
|
return $"group_concat({result} separator '{separator}') ";
|
||||||
|
}
|
||||||
public override string DateDiff(MethodCallExpressionModel model)
|
public override string DateDiff(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
@ -57,6 +57,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public partial class OracleMethod : DefaultDbMethod, IDbMethods
|
public partial class OracleMethod : DefaultDbMethod, IDbMethods
|
||||||
{
|
{
|
||||||
|
public override string GetStringJoinSelector(string result, string separator)
|
||||||
|
{
|
||||||
|
return $"listagg(to_char({result}),'{separator}') within group(order by {result}) ";
|
||||||
|
}
|
||||||
public override string HasValue(MethodCallExpressionModel model)
|
public override string HasValue(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
@ -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];
|
||||||
|
@ -14,6 +14,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public class SqliteMethod : DefaultDbMethod, IDbMethods
|
public class SqliteMethod : DefaultDbMethod, IDbMethods
|
||||||
{
|
{
|
||||||
|
public override string GetStringJoinSelector(string result, string separator)
|
||||||
|
{
|
||||||
|
return $"group_concat({result},'{separator},') ";
|
||||||
|
}
|
||||||
public override string DateDiff(MethodCallExpressionModel model)
|
public override string DateDiff(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = (DateType)(Enum.Parse(typeof(DateType), model.Args[0].MemberValue.ObjToString()));
|
var parameter = (DateType)(Enum.Parse(typeof(DateType), model.Args[0].MemberValue.ObjToString()));
|
||||||
|
Loading…
Reference in New Issue
Block a user