mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Merge branch 'master' of gitee.com:sunkaixuan/sqlsugar_orm_4-0
This commit is contained in:
commit
2122397530
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubAndIF : ISubOperation
|
||||
{
|
||||
public bool HasWhere
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "WhereIF"; }
|
||||
}
|
||||
|
||||
public Expression Expression
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
public ExpressionContext Context
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string GetValue(Expression expression)
|
||||
{
|
||||
var exp = expression as MethodCallExpression;
|
||||
object value = null;
|
||||
try
|
||||
{
|
||||
value = ExpressionTool.DynamicInvoke(exp.Arguments[0]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.WhereIFCheck,exp.Arguments[0].ToString());
|
||||
}
|
||||
var isWhere= Convert.ToBoolean(value);
|
||||
if (!Convert.ToBoolean(isWhere)) {
|
||||
return "";
|
||||
}
|
||||
var argExp = exp.Arguments[1];
|
||||
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, SubTools.GetSubReplace(this.Context));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -87,6 +87,16 @@ namespace SqlSugar
|
||||
{
|
||||
item = items.First(s => s is SubAnd);
|
||||
}
|
||||
|
||||
if (item is SubWhereIF && hasWhere == false)
|
||||
{
|
||||
hasWhere = true;
|
||||
}
|
||||
else if (item is SubWhereIF)
|
||||
{
|
||||
item = items.First(s => s is SubAndIF);
|
||||
}
|
||||
|
||||
item.Context = this.context;
|
||||
item.Expression = exp;
|
||||
return item;
|
||||
|
@ -17,6 +17,7 @@ namespace SqlSugar
|
||||
new SubWhere(){ Context=Context },
|
||||
new SubWhereIF(){ Context=Context },
|
||||
new SubAnd(){ Context=Context },
|
||||
new SubAndIF(){ Context=Context },
|
||||
new SubAny(){ Context=Context },
|
||||
new SubNotAny(){ Context=Context },
|
||||
new SubBegin(){ Context=Context },
|
||||
|
@ -106,6 +106,7 @@
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubSelectDefault.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubNotAny.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubTop.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubAndIF.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhereIF.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Subquerable.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhere.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user