mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Update core
This commit is contained in:
parent
5cdb0cceff
commit
72e829f4b7
@ -41,7 +41,7 @@ namespace SqlSugar
|
||||
this.Context.MappingTables.Add(helper.EntityInfo.EntityName, helper.EntityInfo.DbTableName);
|
||||
}
|
||||
|
||||
public void InitTables<T>(Type [] types)
|
||||
public void InitTables(Type [] types)
|
||||
{
|
||||
foreach (var type in types)
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ namespace SqlSugar
|
||||
#region Core
|
||||
private async Task<int> _BulkUpdate(List<T> datas, string[] whereColumns, string[] updateColumns)
|
||||
{
|
||||
Begin(datas);
|
||||
Begin(datas,false);
|
||||
Check.Exception(whereColumns == null || whereColumns.Count() == 0, "where columns count=0 or need primary key");
|
||||
Check.Exception(updateColumns == null || updateColumns.Count() == 0, "set columns count=0");
|
||||
var isAuto = this.context.CurrentConnectionConfig.IsAutoCloseConnection;
|
||||
@ -94,38 +94,40 @@ namespace SqlSugar
|
||||
this.context.DbMaintenance.DropTable(dt.TableName);
|
||||
this.context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
|
||||
buider.CloseDb();
|
||||
End(datas);
|
||||
End(datas, false);
|
||||
return result;
|
||||
}
|
||||
private async Task<int> _BulkCopy(List<T> datas)
|
||||
{
|
||||
Begin(datas);
|
||||
Begin(datas,true);
|
||||
DataTable dt = ToDdateTable(datas);
|
||||
IFastBuilder buider =GetBuider();
|
||||
buider.Context = context;
|
||||
var result = await buider.ExecuteBulkCopyAsync(dt);
|
||||
End(datas);
|
||||
End(datas,true);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AOP
|
||||
private void End(List<T> datas)
|
||||
private void End(List<T> datas,bool isAdd)
|
||||
{
|
||||
var title = isAdd ? "BulkCopy" : "BulkUpdate";
|
||||
this.context.Ado.IsEnableLogEvent = isLog;
|
||||
if (this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted != null)
|
||||
{
|
||||
this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted($"End bulkcopy name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now}" , new SugarParameter[] { });
|
||||
this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted($"End {title} name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now}" , new SugarParameter[] { });
|
||||
}
|
||||
}
|
||||
|
||||
private void Begin(List<T> datas)
|
||||
private void Begin(List<T> datas,bool isAdd)
|
||||
{
|
||||
var title = isAdd ? "BulkCopy" : "BulkUpdate";
|
||||
isLog = this.context.Ado.IsEnableLogEvent;
|
||||
this.context.Ado.IsEnableLogEvent = false;
|
||||
if (this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting != null)
|
||||
{
|
||||
this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting($"Begin bulkcopy name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now} ", new SugarParameter[] { });
|
||||
this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting($"Begin {title} name:{entityInfo.DbTableName} ,count: {datas.Count},current time: {DateTime.Now} ", new SugarParameter[] { });
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -92,7 +92,7 @@ namespace SqlSugar
|
||||
private object ValueConverter(EntityColumnInfo columnInfo, object value)
|
||||
{
|
||||
if (value == null)
|
||||
return value;
|
||||
return DBNull.Value;
|
||||
if (value is DateTime && (DateTime)value == DateTime.MinValue)
|
||||
{
|
||||
value = Convert.ToDateTime("1900-01-01");
|
||||
|
@ -125,6 +125,9 @@ namespace SqlSugar
|
||||
var other = messageList.Where(it => it.StorageType == StorageType.Other).ToList();
|
||||
StorageableResult<T> result = new StorageableResult<T>()
|
||||
{
|
||||
_IsWhereColumn= this.whereExpression != null,
|
||||
_AsName =asname,
|
||||
_Context=this.Context,
|
||||
AsDeleteable = this.Context.Deleteable<T>().AS(asname),
|
||||
AsUpdateable = this.Context.Updateable(update.Select(it => it.Item).ToList()).AS(asname),
|
||||
AsInsertable = this.Context.Insertable(inset.Select(it => it.Item).ToList()).AS(asname),
|
||||
|
@ -88,5 +88,28 @@ 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 string _AsName { get; set; }
|
||||
internal SqlSugarProvider _Context { get; set; }
|
||||
|
||||
public int BulkCopy()
|
||||
{
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkCopy(InsertList.Select(it=>it.Item).ToList());
|
||||
}
|
||||
public Task<int> BulkCopyAsync()
|
||||
{
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkCopyAsync(InsertList.Select(it => it.Item).ToList());
|
||||
}
|
||||
|
||||
public int BulkUpdate()
|
||||
{
|
||||
Check.Exception(_IsWhereColumn, "Storageable.BulkCopy no support WhereColumns");
|
||||
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");
|
||||
return this._Context.Fastest<T>().AS(_AsName).BulkUpdateAsync(UpdateList.Select(it => it.Item).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user