- 增加 IUpdate.SetSourceIgnore 方法,可实现忽略 null 属性的更新;

This commit is contained in:
28810
2020-05-22 18:20:28 +08:00
parent 97d8c39e1a
commit 99f0dd7391
19 changed files with 246 additions and 21 deletions

View File

@ -55,7 +55,7 @@ namespace FreeSql.Internal.CommonProvider
{
if (_table == null || _table.Type == typeof(object)) return;
foreach (var col in _table.Columns.Values)
if (col.Attribute.CanUpdate == false)
if (col.Attribute.CanUpdate == false && _ignore.ContainsKey(col.Attribute.Name) == false)
_ignore.Add(col.Attribute.Name, true);
}
protected void ClearData()
@ -375,6 +375,16 @@ namespace FreeSql.Internal.CommonProvider
_source.AddRange(source.Where(a => a != null));
return this;
}
public IUpdate<T1> SetSourceIgnore(T1 source, Func<object, bool> ignore)
{
if (ignore == null) throw new ArgumentNullException(nameof(ignore));
var columns = _table.Columns.Values
.Where(col => ignore(_orm.GetEntityValueWithPropertyName(_table.Type, source, col.CsName)))
.Select(col => col.Attribute.Name).ToArray();
IgnoreColumns(columns);
IgnoreCanUpdate();
return SetSource(source);
}
protected void SetPriv(ColumnInfo col, object value)
{