mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
Db.Storageable(list).DefaultAddElseUpdate().ExecuteCommand()
This commit is contained in:
@@ -89,6 +89,20 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public IStorageable<T> DefaultAddElseUpdate()
|
||||
{
|
||||
var column = this.Context.EntityMaintenance.GetEntityInfo<T>().Columns.FirstOrDefault(it=>it.IsPrimarykey);
|
||||
if (column == null) Check.ExceptionEasy("DefaultAddElseUpdate() need primary key", "DefaultAddElseUpdate()这个方法只能用于主键");
|
||||
var defaultValue = default(T);
|
||||
return this.SplitUpdate(it =>
|
||||
{
|
||||
var itemPkValue = column.PropertyInfo.GetValue(it.Item);
|
||||
var result= itemPkValue != null && itemPkValue.ObjToString() != defaultValue.ObjToString();
|
||||
return result;
|
||||
|
||||
}).SplitInsert(it => true);
|
||||
}
|
||||
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
var result = 0;
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace SqlSugar
|
||||
Task<int> ExecuteCommandAsync();
|
||||
int ExecuteSqlBulkCopy();
|
||||
Task<int> ExecuteSqlBulkCopyAsync();
|
||||
IStorageable<T> DefaultAddElseUpdate();
|
||||
}
|
||||
|
||||
public class StorageableInfo<T> where T : class, new()
|
||||
|
||||
Reference in New Issue
Block a user