Add WhereIf override method

This commit is contained in:
sunkaixuan 2017-06-28 12:37:47 +08:00
parent e0bc05cd0a
commit 4085c42e66
3 changed files with 302 additions and 3 deletions

View File

@ -219,6 +219,15 @@ namespace OrmTest.Demo
var list2 = db.Queryable<Student>()
.WhereIF(!string.IsNullOrEmpty(name), it => it.Name == name)
.WhereIF(!string.IsNullOrEmpty(name2), it => it.Name == name2).ToList();
//join
var list3 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
})
.WhereIf(false, (st, sc) => sc.Id == 1)
.WhereIf(false, (st, sc) => st.Id == 1).ToList();
}
public static void Join()
{

View File

@ -223,7 +223,8 @@ namespace SqlSugar
var fieldName = lamResult.GetResultString();
return In(fieldName, inValues);
}
public virtual ISugarQueryable<T> In<TParamter>(List<TParamter> pkValues) {
public virtual ISugarQueryable<T> In<TParamter>(List<TParamter> pkValues)
{
if (pkValues == null || pkValues.Count == 0)
{
Where(SqlBuilder.SqlFalse);
@ -231,7 +232,8 @@ namespace SqlSugar
}
return In(pkValues.ToArray());
}
public virtual ISugarQueryable<T> In<FieldType>(string InFieldName, List<FieldType> inValues) {
public virtual ISugarQueryable<T> In<FieldType>(string InFieldName, List<FieldType> inValues)
{
if (inValues == null || inValues.Count == 0)
{
Where(SqlBuilder.SqlFalse);
@ -239,7 +241,8 @@ namespace SqlSugar
}
return In(InFieldName, inValues.ToArray());
}
public virtual ISugarQueryable<T> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues) {
public virtual ISugarQueryable<T> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
if (inValues == null || inValues.Count == 0)
{
Where(SqlBuilder.SqlFalse);
@ -662,6 +665,18 @@ namespace SqlSugar
_Where(expression);
return this;
}
public ISugarQueryable<T, T2> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
#region Select
@ -773,6 +788,26 @@ namespace SqlSugar
return this;
}
public ISugarQueryable<T, T2, T3> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3> WhereIf(bool isWhere,Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
}
@ -801,6 +836,34 @@ namespace SqlSugar
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
#region Select
@ -894,6 +957,41 @@ namespace SqlSugar
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
#region Select
@ -1006,6 +1104,48 @@ namespace SqlSugar
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
#region Select
@ -1137,6 +1277,55 @@ namespace SqlSugar
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
#region Select
@ -1240,6 +1429,7 @@ namespace SqlSugar
_GroupBy(expression);
return this;
}
#endregion
}
#endregion
@ -1287,6 +1477,62 @@ namespace SqlSugar
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression)
{
if (isWhere)
_Where(expression);
return this;
}
#endregion
#region Select
@ -1404,6 +1650,7 @@ namespace SqlSugar
_GroupBy(expression);
return this;
}
#endregion
}
#endregion

View File

@ -96,6 +96,9 @@ namespace SqlSugar
#region Where
new ISugarQueryable<T, T2> Where(Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2> Where(Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2> WhereIf(bool isWhere,Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
#endregion
#region Select
@ -118,6 +121,10 @@ namespace SqlSugar
new ISugarQueryable<T, T2, T3> Where(Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3> Where(Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3> Where(Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3> WhereIf(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression);
#endregion
#region Select
@ -144,6 +151,11 @@ namespace SqlSugar
ISugarQueryable<T, T2, T3, T4> Where(Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3, T4> Where(Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4> Where(Expression<Func<T, T2, T3, T4, bool>> expression);
new ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression);
#endregion
#region Select
@ -174,6 +186,13 @@ namespace SqlSugar
ISugarQueryable<T, T2, T3, T4, T5> Where(Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> Where(Expression<Func<T, T2, T3, T4, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> Where(Expression<Func<T, T2, T3, T4, T5, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression);
#endregion
#region Select
@ -208,6 +227,13 @@ namespace SqlSugar
ISugarQueryable<T, T2, T3, T4, T5, T6> Where(Expression<Func<T, T2, T3, T4, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> Where(Expression<Func<T, T2, T3, T4, T5, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> Where(Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression);
#endregion
#region Select
@ -246,6 +272,14 @@ namespace SqlSugar
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Where(Expression<Func<T, T2, T3, T4, T5, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Where(Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Where(Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression);
#endregion
#region Select
@ -288,6 +322,15 @@ namespace SqlSugar
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Where(Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Where(Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Where(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIf(bool isWhere, Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression);
#endregion
#region Select