From 9e66580f08a7b9b6c4095394c9e2e2ee25360f54 Mon Sep 17 00:00:00 2001 From: "610262374@qq.com" <610262374@qq.com> Date: Fri, 17 Mar 2017 10:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20WHERE=20IF=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QueryableProvider/QueryableAccessory.cs | 7 +- .../QueryableProvider/QueryableProvider.cs | 64 ++++++++++++++++--- SqlSugar/Interface/IQueryable.cs | 7 ++ 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/SqlSugar/Abstract/QueryableProvider/QueryableAccessory.cs b/SqlSugar/Abstract/QueryableProvider/QueryableAccessory.cs index de4dfedd6..8ec3ac226 100644 --- a/SqlSugar/Abstract/QueryableProvider/QueryableAccessory.cs +++ b/SqlSugar/Abstract/QueryableProvider/QueryableAccessory.cs @@ -32,8 +32,13 @@ namespace SqlSugar _Pars = new List(); _Pars.AddRange(pars); } - protected void Where(Expression> expression, ResolveExpressType type,SqlSugarClient context,ISqlBuilder builder) where T : class, new() + protected void Where(Expression expression,SqlSugarClient context,ISqlBuilder builder) { + ResolveExpressType type = ResolveExpressType.WhereSingle; + if (builder.LambadaQueryBuilder.JoinQueryInfos.IsValuable()) + { + type = ResolveExpressType.WhereMultiple; + } ILambdaExpressions resolveExpress = context.LambdaExpressions; resolveExpress.Resolve(expression, type); BasePars.AddRange(resolveExpress.Parameters); diff --git a/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index c0c56c378..23dcbc297 100644 --- a/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -56,47 +56,93 @@ namespace SqlSugar public virtual ISugarQueryable Where(Expression> expression) { - var type = ResolveExpressType.WhereSingle; - if (this.SqlBuilder.LambadaQueryBuilder.JoinQueryInfos.IsValuable()) - { - type = ResolveExpressType.WhereMultiple; - } - base.Where(expression, type, this.Context, this.SqlBuilder); + base.Where(expression,this.Context, this.SqlBuilder); return this; } - public ISugarQueryable Where(string whereString, object whereObj = null) { base.Where(whereString, whereObj, this.Context, this.SqlBuilder); return this; } - public ISugarQueryable Where(string whereString, object whereObj = null) where T2 : class, new() { base.Where(whereString, whereObj, this.Context, this.SqlBuilder); return this; } - public ISugarQueryable Where(Expression> expression) where T2 : class, new() { + base.Where(expression, this.Context, this.SqlBuilder); return this; } public ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() { + base.Where(expression, this.Context, this.SqlBuilder); return this; } public ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() { + base.Where(expression, this.Context, this.SqlBuilder); return this; } public ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() { + base.Where(expression, this.Context, this.SqlBuilder); return this; } public ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() { + base.Where(expression, this.Context, this.SqlBuilder); return this; } + public virtual ISugarQueryable WhereIF(bool isWhere,Expression> expression) + { + if (!isWhere) return this; + Where(expression); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, string whereString, object whereObj = null) + { + if (!isWhere) return this; + base.Where(whereString, whereObj, this.Context, this.SqlBuilder); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, string whereString, object whereObj = null) where T2 : class, new() + { + if (!isWhere) return this; + base.Where(whereString, whereObj, this.Context, this.SqlBuilder); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() + { + if (!isWhere) return this; + this.Where(expression); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() + { + if (!isWhere) return this; + this.Where(expression); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() + { + if (!isWhere) return this; + this.Where(expression); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() + { + if (!isWhere) return this; + this.Where(expression); + return this; + } + public ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() + { + if (!isWhere) return this; + this.Where(expression); + return this; + } + public ISugarQueryable In(params object[] pkValues) { throw new NotImplementedException(); diff --git a/SqlSugar/Interface/IQueryable.cs b/SqlSugar/Interface/IQueryable.cs index 99a96929b..21428d896 100644 --- a/SqlSugar/Interface/IQueryable.cs +++ b/SqlSugar/Interface/IQueryable.cs @@ -24,6 +24,13 @@ namespace SqlSugar ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new(); ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new(); ISugarQueryable Where(Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new(); + ISugarQueryable WhereIF(bool isWhere, Expression> expression); + ISugarQueryable WhereIF(bool isWhere,string whereString, object whereObj = null); + ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new(); + ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new(); + ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new(); + ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new(); + ISugarQueryable WhereIF(bool isWhere, Expression> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new(); ISugarQueryable In(params object[] pkValues); T InSingle(object pkValue);