Browse Source

Optimize differential logging (Deleteable.As)

pull/40/head
sunkaixuan 1 year ago
parent
commit
09b53789b5
  1. 21
      Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  2. 5
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/DeleteBuilder.cs

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

@ -74,15 +74,16 @@ namespace SqlSugar
public IDeleteable<T> AS(string tableName)
{
if (tableName == null) return this;
var entityName = typeof(T).Name;
IsAs = true;
OldMappingTableList = this.Context.MappingTables;
this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
if (this.Context.MappingTables.Any(it => it.EntityName == entityName))
{
this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
}
this.Context.MappingTables.Add(entityName, tableName);
//var entityName = typeof(T).Name;
//IsAs = true;
//OldMappingTableList = this.Context.MappingTables;
//this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
//if (this.Context.MappingTables.Any(it => it.EntityName == entityName))
//{
// this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
//}
//this.Context.MappingTables.Add(entityName, tableName);
this.DeleteBuilder.AsName = tableName;
return this; ;
}
public IDeleteable<T> EnableDiffLogEventIF(bool isEnableDiffLogEvent, object businessData = null)
@ -628,7 +629,7 @@ namespace SqlSugar
{
List<DiffLogTableInfo> result = new List<DiffLogTableInfo>();
var whereSql = Regex.Replace(sql, ".* WHERE ", "", RegexOptions.Singleline);
var dt = this.Context.Queryable<T>().Filter(null, true).Where(whereSql).AddParameters(parameters).ToDataTable();
var dt = this.Context.Queryable<T>().AS(this.DeleteBuilder.AsName).Filter(null, true).Where(whereSql).AddParameters(parameters).ToDataTable();
if (dt.Rows != null && dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)

5
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/DeleteBuilder.cs

@ -19,6 +19,7 @@ namespace SqlSugar
public StringBuilder sql { get; set; }
public ISqlBuilder Builder { get; set; }
public string TableWithString { get; set; }
public string AsName { get; set; }
public virtual List<string> WhereInfos
{
get
@ -83,6 +84,10 @@ namespace SqlSugar
get
{
var result = Builder.GetTranslationTableName(EntityInfo.EntityName);
if (AsName.HasValue())
{
result = Builder.GetTranslationColumnName(AsName);
}
result += UtilConstants.Space;
if (this.TableWithString.HasValue())
{

Loading…
Cancel
Save