添加 WHERE IF函数

This commit is contained in:
610262374@qq.com
2017-03-17 10:06:24 +08:00
parent 9fd92a0e8b
commit 9e66580f08
3 changed files with 68 additions and 10 deletions

View File

@@ -32,8 +32,13 @@ namespace SqlSugar
_Pars = new List<SugarParameter>();
_Pars.AddRange(pars);
}
protected void Where<T>(Expression<Func<T, bool>> 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);

View File

@@ -56,47 +56,93 @@ namespace SqlSugar
public virtual ISugarQueryable<T> Where(Expression<Func<T, bool>> expression)
{
var type = ResolveExpressType.WhereSingle;
if (this.SqlBuilder.LambadaQueryBuilder.JoinQueryInfos.IsValuable())
{
type = ResolveExpressType.WhereMultiple;
}
base.Where<T>(expression, type, this.Context, this.SqlBuilder);
base.Where(expression,this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> Where(string whereString, object whereObj = null)
{
base.Where<T>(whereString, whereObj, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> Where<T2>(string whereString, object whereObj = null) where T2 : class, new()
{
base.Where<T2>(whereString, whereObj, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> Where<T2>(Expression<Func<T2, bool>> expression) where T2 : class, new()
{
base.Where(expression, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> Where<T2, T3>(Expression<Func<T2, T3, bool>> expression) where T2 : class, new() where T3 : class, new()
{
base.Where(expression, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> Where<T2, T3, T4>(Expression<Func<T2, T3, T4, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new()
{
base.Where(expression, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> Where<T2, T3, T4, T5>(Expression<Func<T2, T3, T4, T5, bool>> 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<T> Where<T2, T3, T4, T5, T6>(Expression<Func<T2, T3, T4, T5, T6, bool>> 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<T> WhereIF(bool isWhere,Expression<Func<T, bool>> expression)
{
if (!isWhere) return this;
Where<T>(expression);
return this;
}
public ISugarQueryable<T> WhereIF(bool isWhere, string whereString, object whereObj = null)
{
if (!isWhere) return this;
base.Where<T>(whereString, whereObj, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> WhereIF<T2>(bool isWhere, string whereString, object whereObj = null) where T2 : class, new()
{
if (!isWhere) return this;
base.Where<T2>(whereString, whereObj, this.Context, this.SqlBuilder);
return this;
}
public ISugarQueryable<T> WhereIF<T2>(bool isWhere, Expression<Func<T2, bool>> expression) where T2 : class, new()
{
if (!isWhere) return this;
this.Where(expression);
return this;
}
public ISugarQueryable<T> WhereIF<T2, T3>(bool isWhere, Expression<Func<T2, T3, bool>> expression) where T2 : class, new() where T3 : class, new()
{
if (!isWhere) return this;
this.Where(expression);
return this;
}
public ISugarQueryable<T> WhereIF<T2, T3, T4>(bool isWhere, Expression<Func<T2, T3, T4, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new()
{
if (!isWhere) return this;
this.Where(expression);
return this;
}
public ISugarQueryable<T> WhereIF<T2, T3, T4, T5>(bool isWhere, Expression<Func<T2, T3, T4, T5, bool>> 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<T> WhereIF<T2, T3, T4, T5, T6>(bool isWhere, Expression<Func<T2, T3, T4, T5, T6, bool>> 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<T> In(params object[] pkValues)
{
throw new NotImplementedException();

View File

@@ -24,6 +24,13 @@ namespace SqlSugar
ISugarQueryable<T> Where<T2, T3, T4>(Expression<Func<T2, T3, T4, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new();
ISugarQueryable<T> Where<T2, T3, T4, T5>(Expression<Func<T2, T3, T4, T5, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new();
ISugarQueryable<T> Where<T2, T3, T4, T5, T6>(Expression<Func<T2, T3, T4, T5, T6, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new();
ISugarQueryable<T> WhereIF(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T> WhereIF(bool isWhere,string whereString, object whereObj = null);
ISugarQueryable<T> WhereIF<T2>(bool isWhere, Expression<Func<T2, bool>> expression) where T2 : class, new();
ISugarQueryable<T> WhereIF<T2, T3>(bool isWhere, Expression<Func<T2, T3, bool>> expression) where T2 : class, new() where T3 : class, new();
ISugarQueryable<T> WhereIF<T2, T3, T4>(bool isWhere, Expression<Func<T2, T3, T4, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new();
ISugarQueryable<T> WhereIF<T2, T3, T4, T5>(bool isWhere, Expression<Func<T2, T3, T4, T5, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new();
ISugarQueryable<T> WhereIF<T2, T3, T4, T5, T6>(bool isWhere, Expression<Func<T2, T3, T4, T5, T6, bool>> expression) where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new();
ISugarQueryable<T> In(params object[] pkValues);
T InSingle(object pkValue);