mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-16 13:09:33 +08:00
Storageable support bulkUpdate(+1)
This commit is contained in:
parent
32ae161a1e
commit
11635d48a4
@ -125,7 +125,7 @@ namespace SqlSugar
|
||||
var other = messageList.Where(it => it.StorageType == StorageType.Other).ToList();
|
||||
StorageableResult<T> result = new StorageableResult<T>()
|
||||
{
|
||||
_IsWhereColumn= this.whereExpression != null,
|
||||
_WhereColumnList= wherecolumnList,
|
||||
_AsName =asname,
|
||||
_Context=this.Context,
|
||||
AsDeleteable = this.Context.Deleteable<T>().AS(asname),
|
||||
|
@ -88,7 +88,7 @@ namespace SqlSugar
|
||||
public IInsertable<T> AsInsertable { get; set; }
|
||||
public IUpdateable<T> AsUpdateable { get; set; }
|
||||
public IDeleteable<T> AsDeleteable { get; set; }
|
||||
internal bool _IsWhereColumn { get; set; }
|
||||
internal List<EntityColumnInfo> _WhereColumnList { get; set; }
|
||||
internal string _AsName { get; set; }
|
||||
internal SqlSugarProvider _Context { get; set; }
|
||||
|
||||
@ -103,13 +103,42 @@ namespace SqlSugar
|
||||
|
||||
public int BulkUpdate()
|
||||
{
|
||||
Check.Exception(_IsWhereColumn, "Storageable.BulkCopy no support WhereColumns");
|
||||
Check.Exception(_WhereColumnList!=null&&_WhereColumnList.Any(),ErrorMessage.GetThrowMessage( "Storageable.BulkUpdate(+0) no support WhereColumns, Use Storageable(+1)", "请使用 Storageable.BulkUpdate +1 重载"));
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkUpdate(UpdateList.Select(it => it.Item).ToList());
|
||||
}
|
||||
public Task<int> BulkUpdateAsync()
|
||||
{
|
||||
Check.Exception(_IsWhereColumn, "Storageable.BulkCopy no support WhereColumns");
|
||||
Check.Exception(_WhereColumnList != null && _WhereColumnList.Any(), ErrorMessage.GetThrowMessage("Storageable.BulkUpdate(+0) no support WhereColumns, Use Storageable(+1)", "请使用 Storageable.BulkUpdate +1 重载"));
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkUpdateAsync(UpdateList.Select(it => it.Item).ToList());
|
||||
}
|
||||
public int BulkUpdate(params string[] UpdateColumns)
|
||||
{
|
||||
|
||||
Check.Exception(UpdateColumns==null, "UpdateColumns is null");
|
||||
if (_WhereColumnList != null && _WhereColumnList.Any())
|
||||
{
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkUpdate(UpdateList.Select(it => it.Item).ToList(), _WhereColumnList.Select(it => it.DbColumnName).ToArray(), UpdateColumns);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pkColumns = this._Context.EntityMaintenance.GetEntityInfo<T>().Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToArray();
|
||||
Check.Exception(pkColumns.Count()==0,"need primary key");
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkUpdate(UpdateList.Select(it => it.Item).ToList(), pkColumns, UpdateColumns);
|
||||
}
|
||||
}
|
||||
public async Task<int> BulkUpdateAsync(params string[] UpdateColumns)
|
||||
{
|
||||
Check.Exception(UpdateColumns == null, "UpdateColumns is null");
|
||||
if (_WhereColumnList != null && _WhereColumnList.Any())
|
||||
{
|
||||
return await this._Context.Fastest<T>().AS(_AsName).BulkUpdateAsync(UpdateList.Select(it => it.Item).ToList(), _WhereColumnList.Select(it => it.DbColumnName).ToArray(), UpdateColumns);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pkColumns = this._Context.EntityMaintenance.GetEntityInfo<T>().Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToArray();
|
||||
Check.Exception(pkColumns.Count() == 0, "need primary key");
|
||||
return await this._Context.Fastest<T>().AS(_AsName).BulkUpdateAsync(UpdateList.Select(it => it.Item).ToList(), pkColumns, UpdateColumns);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user