mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-28 16:37:58 +08:00
Code optimization
This commit is contained in:
parent
b1dd6c96e5
commit
dcf07e6793
@ -249,12 +249,8 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
private IDeleteable<T> CopyDeleteable() {
|
||||
var asyncContext = this.Context.CopyContext(this.Context.Utilities.TranslateCopy(this.Context.CurrentConnectionConfig));
|
||||
var asyncContext = this.Context.Utilities.CopyCurrentContext(this.Context,true);
|
||||
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 asyncDeleteable = asyncContext.Deleteable<T>();
|
||||
var asyncDeleteBuilder = asyncDeleteable.DeleteBuilder;
|
||||
|
@ -307,12 +307,8 @@ namespace SqlSugar
|
||||
}
|
||||
private IInsertable<T> CopyInsertable()
|
||||
{
|
||||
var asyncContext = this.Context.CopyContext(this.Context.Utilities.TranslateCopy(this.Context.CurrentConnectionConfig));
|
||||
var asyncContext = this.Context.Utilities.CopyCurrentContext(this.Context,true);
|
||||
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;
|
||||
|
@ -1024,9 +1024,7 @@ namespace SqlSugar
|
||||
foreach (var item in result)
|
||||
{
|
||||
var contextProperty = item.GetType().GetProperty("Context");
|
||||
ConnectionConfig config = new ConnectionConfig();
|
||||
config = this.Context.CurrentConnectionConfig;
|
||||
SqlSugarClient newClient = this.Context.CopyContext(config);
|
||||
SqlSugarClient newClient = this.Context.Utilities.CopyCurrentContext(this.Context);
|
||||
contextProperty.SetValue(item, newClient, null);
|
||||
}
|
||||
}
|
||||
@ -1034,12 +1032,8 @@ namespace SqlSugar
|
||||
}
|
||||
private ISugarQueryable<T> CopyQueryable()
|
||||
{
|
||||
var asyncContext = this.Context.CopyContext(this.Context.Utilities.TranslateCopy(this.Context.CurrentConnectionConfig));
|
||||
var asyncContext = this.Context.Utilities.CopyCurrentContext(this.Context,true);
|
||||
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 asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty);
|
||||
var asyncQueryableBuilder = asyncQueryable.QueryBuilder;
|
||||
|
@ -311,12 +311,8 @@ namespace SqlSugar
|
||||
}
|
||||
private IUpdateable<T> CopyUpdateable()
|
||||
{
|
||||
var asyncContext = this.Context.CopyContext(this.Context.Utilities.TranslateCopy(this.Context.CurrentConnectionConfig));
|
||||
var asyncContext = this.Context.Utilities.CopyCurrentContext(this.Context,true);
|
||||
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 asyncUpdateable = asyncContext.Updateable<T>(this.UpdateObjs);
|
||||
var asyncUpdateableBuilder = asyncUpdateable.UpdateBuilder;
|
||||
|
@ -222,6 +222,20 @@ namespace SqlSugar
|
||||
return DeserializeObject<T>(jsonString);
|
||||
}
|
||||
}
|
||||
public SqlSugarClient CopyCurrentContext(SqlSugarClient context,bool isCopyEvents=false)
|
||||
{
|
||||
var newClient = new SqlSugarClient(this.TranslateCopy(context.CurrentConnectionConfig));
|
||||
newClient.MappingColumns = this.TranslateCopy(context.MappingColumns);
|
||||
newClient.MappingTables = this.TranslateCopy(context.MappingTables);
|
||||
newClient.IgnoreColumns = this.TranslateCopy(context.IgnoreColumns);
|
||||
if (isCopyEvents) {
|
||||
newClient.Ado.IsEnableLogEvent = context.Ado.IsEnableLogEvent;
|
||||
newClient.Ado.LogEventStarting = context.Ado.LogEventStarting;
|
||||
newClient.Ado.LogEventCompleted = context.Ado.LogEventCompleted;
|
||||
newClient.Ado.ProcessingEventStartingSQL = context.Ado.ProcessingEventStartingSQL;
|
||||
}
|
||||
return newClient;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DataTable
|
||||
|
@ -16,6 +16,7 @@ namespace SqlSugar
|
||||
string SerializeObject(object value);
|
||||
T DeserializeObject<T>(string value);
|
||||
T TranslateCopy<T>(T sourceObject);
|
||||
SqlSugarClient CopyCurrentContext(SqlSugarClient context, bool isCopyEvents = false);
|
||||
dynamic DataTableToDynamic(DataTable table);
|
||||
ICacheManager<T> GetCacheInstance<T>();
|
||||
void RemoveCacheAll();
|
||||
|
@ -50,7 +50,7 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Rewritable Methods
|
||||
#region Util Methods
|
||||
[Obsolete("Use SqlSugarClient.Utilities")]
|
||||
public virtual IRewritableMethods RewritableMethods
|
||||
{
|
||||
@ -546,14 +546,6 @@ namespace SqlSugar
|
||||
this.Ado.Dispose();
|
||||
}
|
||||
}
|
||||
internal SqlSugarClient CopyContext(ConnectionConfig config)
|
||||
{
|
||||
var newClient = new SqlSugarClient(config);
|
||||
newClient.MappingColumns = this.Context.MappingColumns;
|
||||
newClient.MappingTables = this.Context.MappingTables;
|
||||
newClient.IgnoreColumns = this.Context.IgnoreColumns;
|
||||
return newClient;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user