diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 7f25f6404..be146509a 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -423,6 +423,25 @@ namespace SqlSugar { return WhereColumns(new List> { dictionary }); } + public ISugarQueryable WhereColumns(Dictionary columns, bool ignoreDefaultValue) + { + if (ignoreDefaultValue == false || columns == null) + { + return WhereColumns(columns); + } + else + { + var newColumns = new Dictionary(); + foreach (var item in columns) + { + if (!UtilMethods.IsDefaultValue(item.Value)) + { + newColumns.Add(item.Key, item.Value); + } + } + return WhereColumns(newColumns); + } + } public ISugarQueryable WhereColumns(List> list) { List conditionalModels = new List(); diff --git a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs index d95f989e5..2acdbc538 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs @@ -54,6 +54,7 @@ namespace SqlSugar ISugarQueryable WhereClassByPrimaryKey(List list); ISugarQueryable WhereClassByPrimaryKey(T data) ; ISugarQueryable WhereColumns(List> columns); + ISugarQueryable WhereColumns(Dictionary columns, bool ignoreDefaultValue); ISugarQueryable WhereColumns(Dictionary columns); ISugarQueryable TranLock(DbLockType LockType = DbLockType.Wait); ISugarQueryable Where(Expression> expression); diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index 365f6fc22..196885c6b 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -17,6 +17,12 @@ namespace SqlSugar public class UtilMethods { + internal static bool IsDefaultValue(object value) + { + if (value == null) return true; + return value.Equals(UtilMethods.GetDefaultValue(value.GetType())); + } + internal static DateTime ConvertFromDateTimeOffset(DateTimeOffset dateTime) { if (dateTime.Offset.Equals(TimeSpan.Zero))