diff --git a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs index 99e0e1be4..5e6327a3a 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs @@ -219,6 +219,15 @@ namespace OrmTest.Demo var list2 = db.Queryable() .WhereIF(!string.IsNullOrEmpty(name), it => it.Name == name) .WhereIF(!string.IsNullOrEmpty(name2), it => it.Name == name2).ToList(); + + + + //join + var list3 = db.Queryable((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() { diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index cee8117ce..de46ec849 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -223,7 +223,8 @@ namespace SqlSugar var fieldName = lamResult.GetResultString(); return In(fieldName, inValues); } - public virtual ISugarQueryable In(List pkValues) { + public virtual ISugarQueryable In(List pkValues) + { if (pkValues == null || pkValues.Count == 0) { Where(SqlBuilder.SqlFalse); @@ -231,7 +232,8 @@ namespace SqlSugar } return In(pkValues.ToArray()); } - public virtual ISugarQueryable In(string InFieldName, List inValues) { + public virtual ISugarQueryable In(string InFieldName, List inValues) + { if (inValues == null || inValues.Count == 0) { Where(SqlBuilder.SqlFalse); @@ -239,7 +241,8 @@ namespace SqlSugar } return In(InFieldName, inValues.ToArray()); } - public virtual ISugarQueryable In(Expression> expression, List inValues) { + public virtual ISugarQueryable In(Expression> expression, List inValues) + { if (inValues == null || inValues.Count == 0) { Where(SqlBuilder.SqlFalse); @@ -662,6 +665,18 @@ namespace SqlSugar _Where(expression); return this; } + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } #endregion #region Select @@ -773,6 +788,26 @@ namespace SqlSugar return this; } + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere,Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } #endregion } @@ -801,6 +836,34 @@ namespace SqlSugar _Where(expression); return this; } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } #endregion #region Select @@ -894,6 +957,41 @@ namespace SqlSugar _Where(expression); return this; } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } #endregion #region Select @@ -1006,6 +1104,48 @@ namespace SqlSugar _Where(expression); return this; } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } #endregion #region Select @@ -1137,6 +1277,55 @@ namespace SqlSugar _Where(expression); return this; } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> 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 WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } + + public ISugarQueryable WhereIf(bool isWhere, Expression> expression) + { + if (isWhere) + _Where(expression); + return this; + } #endregion #region Select @@ -1404,6 +1650,7 @@ namespace SqlSugar _GroupBy(expression); return this; } + #endregion } #endregion diff --git a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs index f06d39bf5..5f57353d3 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs @@ -96,6 +96,9 @@ namespace SqlSugar #region Where new ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + ISugarQueryable WhereIf(bool isWhere,Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select @@ -118,6 +121,10 @@ namespace SqlSugar new ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select @@ -144,6 +151,11 @@ namespace SqlSugar ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + new ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select @@ -174,6 +186,13 @@ namespace SqlSugar ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select @@ -208,6 +227,13 @@ namespace SqlSugar ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select @@ -246,6 +272,14 @@ namespace SqlSugar ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select @@ -288,6 +322,15 @@ namespace SqlSugar ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); ISugarQueryable Where(Expression> expression); + + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); + ISugarQueryable WhereIf(bool isWhere, Expression> expression); #endregion #region Select