mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 01:46:18 +08:00
Synchronization code
This commit is contained in:
parent
5a54230959
commit
45d5528a0e
@ -86,6 +86,16 @@ namespace SqlSugar
|
|||||||
com(updateable);
|
com(updateable);
|
||||||
updateable.ExecuteCommand();
|
updateable.ExecuteCommand();
|
||||||
}
|
}
|
||||||
|
else if (pkColumn.IsPrimarykey == false)
|
||||||
|
{
|
||||||
|
var pk= this._Context.EntityMaintenance.GetEntityInfo<TChild>().Columns.Where(it => it.IsPrimarykey);
|
||||||
|
List<string> ignoreColumns = new List<string>();
|
||||||
|
if (pk.Any())
|
||||||
|
{
|
||||||
|
ignoreColumns.AddRange(pk.Select(it=>it.PropertyName));
|
||||||
|
}
|
||||||
|
x.AsUpdateable.IgnoreColumns(ignoreColumns.ToArray()).ExecuteCommand();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x.AsUpdateable.ExecuteCommand();
|
x.AsUpdateable.ExecuteCommand();
|
||||||
|
@ -26,6 +26,7 @@ namespace SqlSugar
|
|||||||
public string TableWithString { get; set; }
|
public string TableWithString { get; set; }
|
||||||
public List<DbColumnInfo> DbColumnInfoList { get; set; }
|
public List<DbColumnInfo> DbColumnInfoList { get; set; }
|
||||||
public List<string> WhereValues { get; set; }
|
public List<string> WhereValues { get; set; }
|
||||||
|
public string AppendWhere { get; set; }
|
||||||
public List<KeyValuePair<string, string>> SetValues { get; set; }
|
public List<KeyValuePair<string, string>> SetValues { get; set; }
|
||||||
public bool IsNoUpdateNull { get; set; }
|
public bool IsNoUpdateNull { get; set; }
|
||||||
public bool IsNoUpdateDefaultValue { get; set; }
|
public bool IsNoUpdateDefaultValue { get; set; }
|
||||||
|
108
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableFilter.cs
Normal file
108
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableFilter.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class UpdateableFilter<T> where T : class, new()
|
||||||
|
{
|
||||||
|
public T[] DataList { get; set; }
|
||||||
|
public SqlSugarProvider Context { get; set; }
|
||||||
|
public int PageSize { get; internal set; }
|
||||||
|
public string TableName { get; internal set; }
|
||||||
|
public bool IsEnableDiffLogEvent { get; internal set; }
|
||||||
|
public DiffLogModel DiffModel { get; internal set; }
|
||||||
|
public List<string> UpdateColumns { get; internal set; }
|
||||||
|
public int ExecuteCommand()
|
||||||
|
{
|
||||||
|
if (DataList.Count() == 1 && DataList.First() == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
PageSize = 1;
|
||||||
|
var result = 0;
|
||||||
|
var isNoTran = this.Context.Ado.IsNoTran();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
this.Context.Ado.BeginTran();
|
||||||
|
}
|
||||||
|
this.Context.Utilities.PageEach(DataList, PageSize, pageItem =>
|
||||||
|
{
|
||||||
|
result += SetFilterSql(this.Context.Updateable(pageItem.First()).AS(TableName).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).UpdateColumns(UpdateColumns.ToArray())).ExecuteCommand();
|
||||||
|
});
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
this.Context.Ado.CommitTran();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
this.Context.Ado.RollbackTran();
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<int> ExecuteCommandAsync()
|
||||||
|
{
|
||||||
|
if (DataList.Count() == 1 && DataList.First() == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
PageSize = 1;
|
||||||
|
var result = 0;
|
||||||
|
var isNoTran = this.Context.Ado.IsNoTran();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
await this.Context.Ado.BeginTranAsync();
|
||||||
|
}
|
||||||
|
await this.Context.Utilities.PageEachAsync(DataList, PageSize, async pageItem =>
|
||||||
|
{
|
||||||
|
result += await SetFilterSql(this.Context.Updateable(pageItem.First()).AS(TableName).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).UpdateColumns(UpdateColumns.ToArray())).ExecuteCommandAsync();
|
||||||
|
});
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
await this.Context.Ado.CommitTranAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
await this.Context.Ado.RollbackTranAsync();
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private IUpdateable<T> SetFilterSql(IUpdateable<T> updateable)
|
||||||
|
{
|
||||||
|
var queryable = this.Context.Queryable<T>();
|
||||||
|
queryable.QueryBuilder.LambdaExpressions.ParameterIndex = 10000;
|
||||||
|
var sqlobj=queryable.ToSql();
|
||||||
|
var sql= UtilMethods.RemoveBeforeFirstWhere(sqlobj.Key);
|
||||||
|
if (sql!=sqlobj.Key)
|
||||||
|
{
|
||||||
|
updateable.UpdateBuilder.AppendWhere = sql;
|
||||||
|
}
|
||||||
|
if (sqlobj.Value != null)
|
||||||
|
{
|
||||||
|
updateable.UpdateBuilder.Parameters.AddRange(sqlobj.Value);
|
||||||
|
}
|
||||||
|
return updateable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,20 @@ namespace SqlSugar
|
|||||||
public bool IsEnableDiffLogEvent { get; internal set; }
|
public bool IsEnableDiffLogEvent { get; internal set; }
|
||||||
public DiffLogModel DiffModel { get; internal set; }
|
public DiffLogModel DiffModel { get; internal set; }
|
||||||
public List<string> UpdateColumns { get; internal set; }
|
public List<string> UpdateColumns { get; internal set; }
|
||||||
|
|
||||||
|
public UpdateableFilter<T> EnableQueryFilter()
|
||||||
|
{
|
||||||
|
return new UpdateableFilter<T>()
|
||||||
|
{
|
||||||
|
Context= Context,
|
||||||
|
DataList= DataList,
|
||||||
|
DiffModel= DiffModel,
|
||||||
|
IsEnableDiffLogEvent= IsEnableDiffLogEvent,
|
||||||
|
PageSize=PageSize,
|
||||||
|
TableName=TableName,
|
||||||
|
UpdateColumns=UpdateColumns
|
||||||
|
};
|
||||||
|
}
|
||||||
public int ExecuteCommand()
|
public int ExecuteCommand()
|
||||||
{
|
{
|
||||||
if (DataList.Count() == 1 && DataList.First() == null)
|
if (DataList.Count() == 1 && DataList.First() == null)
|
||||||
|
@ -104,6 +104,10 @@ namespace SqlSugar
|
|||||||
return trakRows;
|
return trakRows;
|
||||||
}
|
}
|
||||||
string sql = _ExecuteCommand();
|
string sql = _ExecuteCommand();
|
||||||
|
if (this.UpdateBuilder.AppendWhere.HasValue())
|
||||||
|
{
|
||||||
|
sql += " AND "+ this.UpdateBuilder.AppendWhere;
|
||||||
|
}
|
||||||
if (string.IsNullOrEmpty(sql))
|
if (string.IsNullOrEmpty(sql))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -150,6 +150,7 @@
|
|||||||
<Compile Include="Abstract\SqlBuilderProvider\SqlBuilderProvider_Condition.cs" />
|
<Compile Include="Abstract\SqlBuilderProvider\SqlBuilderProvider_Condition.cs" />
|
||||||
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
|
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
|
||||||
<Compile Include="Abstract\DeleteProvider\DeleteMethodInfo.cs" />
|
<Compile Include="Abstract\DeleteProvider\DeleteMethodInfo.cs" />
|
||||||
|
<Compile Include="Abstract\UpdateProvider\UpdateableFilter.cs" />
|
||||||
<Compile Include="Abstract\UpdateProvider\UpdateablePage.cs" />
|
<Compile Include="Abstract\UpdateProvider\UpdateablePage.cs" />
|
||||||
<Compile Include="Abstract\UpdateProvider\UpdateableProviderT2.cs" />
|
<Compile Include="Abstract\UpdateProvider\UpdateableProviderT2.cs" />
|
||||||
<Compile Include="Abstract\UpdateProvider\UpdateableProviderT3.cs" />
|
<Compile Include="Abstract\UpdateProvider\UpdateableProviderT3.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user