This commit is contained in:
sunkaixuan 2017-09-05 12:32:16 +08:00
parent d955014b02
commit 09e37a23ad
3 changed files with 67 additions and 51 deletions

View File

@ -82,6 +82,55 @@ namespace SqlSugar
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result,setValue, null);
return idValue>0;
}
public Task<int> ExecuteCommandAsync()
{
Task<int> result = new Task<int>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteCommand();
});
return result;
}
public Task<int> ExecuteReturnIdentityAsync()
{
Task<int> result = new Task<int>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteReturnIdentity();
});
return result;
}
public Task<T> ExecuteReturnEntityAsync()
{
Task<T> result = new Task<T>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteReturnEntity();
});
return result;
}
public Task<bool> ExecuteCommandIdentityIntoEntityAsync()
{
Task<bool> result = new Task<bool>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteCommandIdentityIntoEntity();
});
return result;
}
public Task<long> ExecuteReturnBigIdentityAsync()
{
Task<long> result = new Task<long>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteReturnBigIdentity();
});
return result;
}
#endregion
#region Setting
@ -276,56 +325,6 @@ namespace SqlSugar
asyncInsertableBuilder.TableWithString = this.InsertBuilder.TableWithString;
return asyncInsertable;
}
public Task<int> ExecuteCommandAsync()
{
Task<int> result = new Task<int>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteCommand();
});
return result;
}
public Task<int> ExecuteReturnIdentityAsync()
{
Task<int> result = new Task<int>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteReturnIdentity();
});
return result;
}
public Task<T> ExecuteReturnEntityAsync()
{
Task<T> result = new Task<T>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteReturnEntity();
});
return result;
}
public Task<bool> ExecuteCommandIdentityIntoEntityAsync()
{
Task<bool> result = new Task<bool>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteCommandIdentityIntoEntity();
});
return result;
}
public Task<long> ExecuteReturnBigIdentityAsync()
{
Task<long> result = new Task<long>(() =>
{
IInsertable<T> asyncInsertable = CopyInsertable();
return asyncInsertable.ExecuteReturnBigIdentity();
});
return result;
}
#endregion
}
}

View File

@ -13,7 +13,7 @@ namespace SqlSugar
public SqlSugarClient Context { get; internal set; }
public EntityInfo EntityInfo { get; internal set; }
public ISqlBuilder SqlBuilder { get; internal set; }
public UpdateBuilder UpdateBuilder { get; internal set; }
public UpdateBuilder UpdateBuilder { get; set; }
public IAdo Ado { get { return Context.Ado; } }
public T[] UpdateObjs { get; set; }
public bool IsMappingTable { get { return this.Context.MappingTables != null && this.Context.MappingTables.Any(); } }
@ -33,6 +33,9 @@ namespace SqlSugar
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
return this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
}
public Task<int> ExecuteCommandAsync() {
return null;
}
public IUpdateable<T> AS(string tableName)
{
var entityName = typeof(T).Name;
@ -298,5 +301,17 @@ namespace SqlSugar
this.Context.MappingTables = OldMappingTableList;
}
}
private IUpdateable<T> CopyUpdateable()
{
var asyncContext = this.Context.CopyContext(this.Context.RewritableMethods.TranslateCopy(this.Context.CurrentConnectionConfig));
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
asyncContext.Ado.IsEnableLogEvent = this.Context.Ado.IsEnableLogEvent;
asyncContext.Ado.LogEventStarting = this.Context.Ado.LogEventStarting;
asyncContext.Ado.LogEventCompleted = this.Context.Ado.LogEventCompleted;
asyncContext.Ado.ProcessingEventStartingSQL = this.Context.Ado.ProcessingEventStartingSQL;
return null;
}
}
}

View File

@ -9,7 +9,9 @@ namespace SqlSugar
{
public interface IUpdateable<T>
{
UpdateBuilder UpdateBuilder { get; set; }
int ExecuteCommand();
Task<int> ExecuteCommandAsync();
IUpdateable<T> AS(string tableName);
IUpdateable<T> With(string lockString);
IUpdateable<T> Where(bool isNoUpdateNull,bool IsOffIdentity = false);