This commit is contained in:
sunkaixuan 2017-09-05 12:18:00 +08:00
parent 8c148fd12a
commit d955014b02
5 changed files with 87 additions and 1 deletions

View File

@ -55,6 +55,11 @@ namespace OrmTest.Demo
var t10 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteCommand();
var t11 = db.Insertable(insertObjs.ToArray()).ExecuteCommand();
var t12 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReturnIdentityAsync();
t12.Start();
t12.Wait();
}
}
}

View File

@ -255,6 +255,77 @@ namespace SqlSugar
this.Context.MappingTables = OldMappingTableList;
}
}
private IInsertable<T> CopyInsertable()
{
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;
var asyncInsertable = asyncContext.Insertable<T>(this.InsertObjs);
var asyncInsertableBuilder = asyncInsertable.InsertBuilder;
asyncInsertableBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList;
asyncInsertableBuilder.EntityInfo = this.InsertBuilder.EntityInfo;
asyncInsertableBuilder.Parameters = this.InsertBuilder.Parameters;
asyncInsertableBuilder.sql = this.InsertBuilder.sql;
asyncInsertableBuilder.IsNoInsertNull = this.InsertBuilder.IsNoInsertNull;
asyncInsertableBuilder.IsReturnIdentity = this.InsertBuilder.IsReturnIdentity;
asyncInsertableBuilder.EntityInfo = this.InsertBuilder.EntityInfo;
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

@ -1029,6 +1029,8 @@ namespace SqlSugar
asyncQueryableBuilder.EntityType = this.QueryBuilder.EntityType;
asyncQueryableBuilder.EntityName = this.QueryBuilder.EntityName;
asyncQueryableBuilder.Parameters = this.QueryBuilder.Parameters;
asyncQueryableBuilder.TableShortName = this.QueryBuilder.TableShortName;
asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString;
return asyncQueryable;
}
#endregion

View File

@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,6 +9,7 @@ namespace SqlSugar
public class ModelContext
{
[SugarColumn(IsIgnore = true)]
[JsonIgnore]
public SqlSugarClient Context { get; set; }
public ISugarQueryable<T> CreateMapping<T>() where T : class, new()
{

View File

@ -9,11 +9,17 @@ namespace SqlSugar
{
public interface IInsertable<T>
{
InsertBuilder InsertBuilder { get; set; }
int ExecuteCommand();
Task<int> ExecuteCommandAsync();
int ExecuteReturnIdentity();
Task<int> ExecuteReturnIdentityAsync();
T ExecuteReturnEntity();
Task<T> ExecuteReturnEntityAsync();
bool ExecuteCommandIdentityIntoEntity();
Task<bool> ExecuteCommandIdentityIntoEntityAsync();
long ExecuteReturnBigIdentity();
Task<long> ExecuteReturnBigIdentityAsync();
IInsertable<T> AS(string tableName);
IInsertable<T> With(string lockString);
IInsertable<T> InsertColumns(Expression<Func<T, object>> columns);