Update .net core project

This commit is contained in:
sunkaixuan 2022-08-03 20:49:11 +08:00
parent 6c525a5abf
commit 01e7f52196
10 changed files with 140 additions and 1 deletions

View File

@ -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)
{
var parameter = model.Args[0];
@ -556,5 +561,9 @@ namespace SqlSugar
{
return null;
}
public virtual string GetForXmlPath()
{
return null;
}
}
}

View File

@ -33,6 +33,7 @@ namespace SqlSugar
string StartsWith(MethodCallExpressionModel model);
string EndsWith(MethodCallExpressionModel model);
string ToInt32(MethodCallExpressionModel model);
string GetStringJoinSelector(string result,string separator);
string ToInt64(MethodCallExpressionModel model);
string ToString(MethodCallExpressionModel model);
string ToVarchar(MethodCallExpressionModel model);
@ -87,5 +88,6 @@ namespace SqlSugar
string Desc(MethodCallExpressionModel model);
string Stuff(MethodCallExpressionModel model);
string GetDateString(string dateValue,string format);
string GetForXmlPath();
}
}

View File

@ -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());
}
}
}
}
}

View File

@ -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;

View File

@ -35,7 +35,8 @@ namespace SqlSugar
new SubAs(){Context=Context},
new SubHaving(){ Context=Context},
new SubWithNolock(){ Context=Context },
new SubEnableTableFilter(){ Context=Context }
new SubEnableTableFilter(){ Context=Context },
new SubSelectStringJoin{ Context=Context }
};
}

View File

@ -84,6 +84,11 @@ namespace SqlSugar
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
{
return default(TResult);

View File

@ -14,6 +14,10 @@ namespace SqlSugar
}
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)
{
var parameter = model.Args[0];

View File

@ -57,6 +57,10 @@ namespace SqlSugar
}
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)
{
var parameter = model.Args[0];

View File

@ -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];

View File

@ -14,6 +14,10 @@ namespace SqlSugar
}
public class SqliteMethod : DefaultDbMethod, IDbMethods
{
public override string GetStringJoinSelector(string result, string separator)
{
return $"group_concat({result},'{separator},') ";
}
public override string DateDiff(MethodCallExpressionModel model)
{
var parameter = (DateType)(Enum.Parse(typeof(DateType), model.Args[0].MemberValue.ObjToString()));