mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Support Subquery.ToList()
This commit is contained in:
parent
bb664be191
commit
960aec2695
@ -33,6 +33,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Splicing basic
|
||||
public Dictionary<string, object> SubToListParameters { get; set; }
|
||||
public bool IsCrossQueryWithAttr { get; set; }
|
||||
public Dictionary<string,string> CrossQueryItems { get; set; }
|
||||
public bool IsSelectSingleFiledJson { get; set; }
|
||||
|
@ -135,6 +135,14 @@ namespace SqlSugar
|
||||
var value = GetNewExpressionValue(item);
|
||||
parameter.Context.Result.Append($" {value} AS {asName} ");
|
||||
}
|
||||
else if (IsSubToList(item))
|
||||
{
|
||||
var value = GetNewExpressionValue(item);
|
||||
if (this.Context.SugarContext.QueryBuilder.SubToListParameters == null)
|
||||
this.Context.SugarContext.QueryBuilder.SubToListParameters = new Dictionary<string, object>();
|
||||
this.Context.SugarContext.QueryBuilder.SubToListParameters.Add(asName, value);
|
||||
throw new Exception("子查询ToList开发中..");
|
||||
}
|
||||
else
|
||||
{
|
||||
asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType);
|
||||
|
@ -12,6 +12,21 @@ namespace SqlSugar
|
||||
public partial class BaseResolve
|
||||
{
|
||||
|
||||
private static bool IsSubToList(Expression item)
|
||||
{
|
||||
return ExpressionTool.GetMethodName(item) == "ToList" && IsSubquery(item);
|
||||
}
|
||||
|
||||
private static bool IsSubquery(Expression item)
|
||||
{
|
||||
var method = (item as MethodCallExpression);
|
||||
if (method == null)
|
||||
return false;
|
||||
if (method.Object == null)
|
||||
return false;
|
||||
return method.Object.Type.Name.StartsWith("Subquery");
|
||||
}
|
||||
|
||||
private bool IsExtSqlFuncObj(Expression item)
|
||||
{
|
||||
return this.Context.SqlFuncServices != null && item is MethodCallExpression && this.Context.SqlFuncServices.Any(it => it.UniqueMethodName == ExpressionTool.GetMethodName(item));
|
||||
|
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubToList:ISubOperation
|
||||
{
|
||||
public bool HasWhere
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ToList";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
InitType(exp);
|
||||
|
||||
|
||||
return "*,@SugarlistRowIndex as SugarlistRowIndex";
|
||||
}
|
||||
|
||||
private void InitType(MethodCallExpression exp)
|
||||
{
|
||||
if (exp.Arguments.Count > 0)
|
||||
{
|
||||
foreach (var arg in (exp.Arguments[0] as LambdaExpression).Parameters)
|
||||
{
|
||||
if (this.Context.InitMappingInfo != null)
|
||||
{
|
||||
this.Context.InitMappingInfo(arg.Type);
|
||||
this.Context.RefreshMapping();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShortName(MethodCallExpression exp, string result)
|
||||
{
|
||||
if (exp.Arguments[0] is LambdaExpression)
|
||||
{
|
||||
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)
|
||||
{
|
||||
var parameters = (exp.Arguments[1] as LambdaExpression).Parameters;
|
||||
if (parameters != null && parameters.Count > 0)
|
||||
{
|
||||
this.Context.CurrentShortName = this.Context.GetTranslationColumnName(parameters[0].ObjToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -37,7 +37,8 @@ namespace SqlSugar
|
||||
new SubWithNolock(){ Context=Context },
|
||||
new SubEnableTableFilter(){ Context=Context },
|
||||
new SubSelectStringJoin{ Context=Context },
|
||||
new SubDistinctCount{ Context=Context }
|
||||
new SubDistinctCount{ Context=Context },
|
||||
new SubToList{ Context=Context}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -170,5 +170,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<T> ToList()
|
||||
{
|
||||
return new List<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,7 @@
|
||||
<Compile Include="ExpressionsToSql\ResolveItems\MethodCallExpressionResolve_BaseDateFomat.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubDistinctCount.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectStringJoin.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubToList.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
|
||||
<Compile Include="Interface\ICustomConditionalFunc.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user