Browse Source

Code optimization

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
dcf07e6793
  1. 6
      Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  2. 6
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  3. 10
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  4. 6
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  5. 14
      Src/Asp.Net/SqlSugar/Infrastructure/RewritableMethods.cs
  6. 1
      Src/Asp.Net/SqlSugar/Interface/IRewritableMethods.cs
  7. 10
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs

6
Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs

@ -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;

6
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -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;

10
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -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;

6
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -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;

14
Src/Asp.Net/SqlSugar/Infrastructure/RewritableMethods.cs

@ -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

1
Src/Asp.Net/SqlSugar/Interface/IRewritableMethods.cs

@ -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();

10
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -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…
Cancel
Save