diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index d83823f7b..f85c5738e 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -426,6 +426,50 @@ namespace SqlSugar AppendSets(); return this; } + + + public IUpdateable SetColumns(Expression> columns, bool appendColumnsByDataFilter) + { + ThrowUpdateByObject(); + var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.Update); + var resultArray = expResult.GetResultArray(); + Check.ArgumentNullException(resultArray, "UpdateColumns Parameter error, UpdateColumns(it=>new T{ it.id=1}) is valid, UpdateColumns(it=>T) is error"); + if (resultArray.HasValue()) + { + foreach (var item in resultArray) + { + string key = SqlBuilder.GetNoTranslationColumnName(item); + var value = item; + if (value.Contains("= \"SYSDATE\"")) + { + value = value.Replace("= \"SYSDATE\"", "= SYSDATE"); + } + UpdateBuilder.SetValues.Add(new KeyValuePair(SqlBuilder.GetTranslationColumnName(key), value)); + } + } + if (appendColumnsByDataFilter) + { + var data = ((UpdateableProvider)this.Context.Updateable(new T() { })).UpdateObjs.First(); + foreach (var item in this.EntityInfo.Columns.Where(it => !it.IsPrimarykey && !it.IsIgnore && !it.IsOnlyIgnoreUpdate)) + { + var value = item.PropertyInfo.GetValue(data); + if (value != null) + { + if (!value.Equals(UtilMethods.GetDefaultValue(item.UnderType))) + { + var pName = this.SqlBuilder.SqlParameterKeyWord + item.PropertyName + 1000; + var p = new SugarParameter(pName, value); + this.UpdateBuilder.Parameters.Add(p); + UpdateBuilder.SetValues.Add(new KeyValuePair(SqlBuilder.GetTranslationColumnName(item.DbColumnName), SqlBuilder.GetTranslationColumnName(item.DbColumnName)+"="+pName)); + } + } + } + } + this.UpdateBuilder.DbColumnInfoList = UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList(); + CheckTranscodeing(false); + AppendSets(); + return this; + } public IUpdateable SetColumns(Expression> columns) { ThrowUpdateByObject(); diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs index bc7348f87..03844dc66 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs @@ -68,6 +68,7 @@ namespace SqlSugar /// /// IUpdateable SetColumns(Expression> columns); + IUpdateable SetColumns(Expression> columns,bool appendColumnsByDataFilter); IUpdateable SetColumns(string fieldName,object fieldValue); IUpdateable SetColumns(Expression> filedNameExpression, object fieldValue); diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec index ed758a65a..c78dcf1af 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ SqlSugarCore - 5.1.3.2-preview06 + 5.1.3.2-preview07 sunkaixuan 果糖大数据科技 http://www.apache.org/licenses/LICENSE-2.0.html