mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Subquery
This commit is contained in:
parent
18adc06243
commit
e7ddef1bee
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubAnd:ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "And"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 401;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(ExpressionContext context, Expression expression)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
var argExp = exp.Arguments[0];
|
||||||
|
var result = "AND " + SubTools.GetMethodValue(context, argExp, ResolveExpressType.WhereMultiple);
|
||||||
|
var selfParameterName = context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
|
result = result.Replace(selfParameterName, string.Empty);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SqlSugar.ExpressionsToSql.Subquery
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public class SubWhere: ISubOperation
|
public class SubWhere: ISubOperation
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
List<MethodCallExpression> allMethods = new List<MethodCallExpression>();
|
List<MethodCallExpression> allMethods = new List<MethodCallExpression>();
|
||||||
private ExpressionContext context = null;
|
private ExpressionContext context = null;
|
||||||
public SubResolve(MethodCallExpression expression, ExpressionContext context,Expression oppsiteExpression)
|
private bool hasWhere;
|
||||||
|
public SubResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
var currentExpression = expression;
|
var currentExpression = expression;
|
||||||
@ -20,7 +21,8 @@ namespace SqlSugar
|
|||||||
var childExpression = (oppsiteExpression as MemberExpression).Expression;
|
var childExpression = (oppsiteExpression as MemberExpression).Expression;
|
||||||
this.context.SingleTableNameSubqueryShortName = (childExpression as ParameterExpression).Name;
|
this.context.SingleTableNameSubqueryShortName = (childExpression as ParameterExpression).Name;
|
||||||
}
|
}
|
||||||
else if (context.IsSingle) {
|
else if (context.IsSingle)
|
||||||
|
{
|
||||||
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
|
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
|
||||||
}
|
}
|
||||||
while (currentExpression != null)
|
while (currentExpression != null)
|
||||||
@ -45,16 +47,25 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var methodName = exp.Method.Name;
|
var methodName = exp.Method.Name;
|
||||||
var item = SubTools.SubItems.First(s => s.Name == methodName);
|
var item = SubTools.SubItems.First(s => s.Name == methodName);
|
||||||
|
if (item is SubWhere && hasWhere == false)
|
||||||
|
{
|
||||||
|
hasWhere = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item = SubTools.SubItems.First(s => s is SubAnd);
|
||||||
|
}
|
||||||
item.Expression = exp;
|
item.Expression = exp;
|
||||||
return item;
|
return item;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
isubList.Insert(0, new SubBegin());
|
isubList.Insert(0, new SubBegin());
|
||||||
if (isubList.Any(it => it is SubAny||it is SubNotAny)) {
|
if (isubList.Any(it => it is SubAny || it is SubNotAny))
|
||||||
|
{
|
||||||
isubList.Add(new SubLeftBracket());
|
isubList.Add(new SubLeftBracket());
|
||||||
isubList.Add(new SubRightBracket());
|
isubList.Add(new SubRightBracket());
|
||||||
isubList.Add(new SubSelectDefault());
|
isubList.Add(new SubSelectDefault());
|
||||||
}
|
}
|
||||||
isubList= isubList.OrderBy(it => it.Sort).ToList();
|
isubList = isubList.OrderBy(it => it.Sort).ToList();
|
||||||
List<string> result = isubList.Select(it =>
|
List<string> result = isubList.Select(it =>
|
||||||
{
|
{
|
||||||
return it.GetValue(this.context, it.Expression);
|
return it.GetValue(this.context, it.Expression);
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||||
<Compile Include="Enum\DbType.cs" />
|
<Compile Include="Enum\DbType.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\ISubAction.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\ISubAction.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubAnd.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubLeftBracket.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubLeftBracket.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubFromTable.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubFromTable.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubAny.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubAny.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user