mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
Add Subquery.SelectJoin
This commit is contained in:
@@ -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];
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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];
|
||||||
|
|||||||
@@ -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()));
|
||||||
|
|||||||
@@ -126,6 +126,7 @@
|
|||||||
<Compile Include="Entities\DbFastestProperties.cs" />
|
<Compile Include="Entities\DbFastestProperties.cs" />
|
||||||
<Compile Include="Entities\DeleteNavOptions.cs" />
|
<Compile Include="Entities\DeleteNavOptions.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Common\NewExpressionInfo.cs" />
|
<Compile Include="ExpressionsToSql\Common\NewExpressionInfo.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectStringJoin.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
|
||||||
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />
|
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user