mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-29 19:56:43 +08:00
Synchronization code
This commit is contained in:
parent
cf9c1436c4
commit
c086b15839
@ -168,7 +168,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
x.AsUpdateable.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData).ExecuteCommand();
|
||||
x.AsUpdateable.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData).ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock);
|
||||
newRoots.Add(item);
|
||||
}
|
||||
}
|
||||
@ -180,7 +180,7 @@ namespace SqlSugar
|
||||
.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent,_RootOptions.DiffLogBizData)
|
||||
.UpdateColumns(_RootOptions.UpdateColumns)
|
||||
.IgnoreColumns(_RootOptions.IgnoreColumns)
|
||||
.ExecuteCommand();
|
||||
.ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock);
|
||||
}
|
||||
}
|
||||
else if (_RootOptions != null && _RootOptions?.IsDiffLogEvent == true)
|
||||
|
@ -98,17 +98,17 @@ namespace SqlSugar
|
||||
|
||||
public virtual List<TResult> ToList<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
//if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0)
|
||||
//{
|
||||
// return NavSelectHelper.GetList(expression, this);
|
||||
// // var list = this.ToList().Select(expression.Compile()).ToList();
|
||||
// // return list;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0)
|
||||
{
|
||||
return NavSelectHelper.GetList(expression, this);
|
||||
// var list = this.ToList().Select(expression.Compile()).ToList();
|
||||
// return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = this.Select(expression).ToList();
|
||||
return list;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int Count()
|
||||
@ -668,21 +668,21 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual List<TResult> ToPageList<TResult>(int pageIndex, int pageSize, ref int totalNumber, Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
//if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0)
|
||||
//{
|
||||
// if (pageIndex == 0)
|
||||
// pageIndex = 1;
|
||||
// var list = this.Clone().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(expression);
|
||||
// var countQueryable = this.Clone();
|
||||
// countQueryable.QueryBuilder.Includes = null;
|
||||
// totalNumber = countQueryable.Count();
|
||||
// return list;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0)
|
||||
{
|
||||
if (pageIndex == 0)
|
||||
pageIndex = 1;
|
||||
var list = this.Clone().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(expression);
|
||||
var countQueryable = this.Clone();
|
||||
countQueryable.QueryBuilder.Includes = null;
|
||||
totalNumber = countQueryable.Count();
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = this.Select(expression).ToPageList(pageIndex, pageSize, ref totalNumber).ToList();
|
||||
return list;
|
||||
//}
|
||||
}
|
||||
}
|
||||
public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber)
|
||||
{
|
||||
|
@ -64,10 +64,20 @@ namespace SqlSugar
|
||||
var sqlObj = this.ToSql();
|
||||
this.Context.Queues.Add(sqlObj.Key, sqlObj.Value);
|
||||
}
|
||||
|
||||
public virtual int ExecuteCommandWithOptLockIF(bool? IsVersionValidation ,bool? IsOptLock=null)
|
||||
{
|
||||
if (IsOptLock==true)
|
||||
{
|
||||
return ExecuteCommandWithOptLock(IsVersionValidation??false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public virtual int ExecuteCommandWithOptLock(bool IsVersionValidation=false)
|
||||
{
|
||||
Check.ExceptionEasy(this.UpdateBuilder.IsListUpdate==true, " OptLock can only be used on a single object, and the argument cannot be List", "乐观锁只能用于单个对象,参数不能是List,如果是一对多操作请更新主表统一用主表验证");
|
||||
Check.ExceptionEasy(UpdateObjs?.Length>1, " OptLock can only be used on a single object, and the argument cannot be List", "乐观锁只能用于单个对象,参数不能是List,如果是一对多操作请更新主表统一用主表验证");
|
||||
var updateData = UpdateObjs.FirstOrDefault();
|
||||
if (updateData == null) return 0;
|
||||
object oldValue = null;
|
||||
@ -111,7 +121,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual async Task<int> ExecuteCommandWithOptLockAsync(bool IsVersionValidation = false)
|
||||
{
|
||||
Check.ExceptionEasy(this.UpdateBuilder.IsListUpdate == true, " OptLock can only be used on a single object, and the argument cannot be List", "乐观锁只能用于单个对象,参数不能是List,如果是一对多操作请更新主表统一用主表验证");
|
||||
Check.ExceptionEasy(UpdateObjs?.Length > 1, " OptLock can only be used on a single object, and the argument cannot be List", "乐观锁只能用于单个对象,参数不能是List,如果是一对多操作请更新主表统一用主表验证");
|
||||
var updateData = UpdateObjs.FirstOrDefault();
|
||||
if (updateData == null) return 0;
|
||||
object oldValue = null;
|
||||
|
@ -38,6 +38,8 @@ namespace SqlSugar
|
||||
public bool IsDiffLogEvent { get; set; }
|
||||
public object DiffLogBizData { get; set; }
|
||||
public string[] IgnoreInsertColumns { get; set; }
|
||||
public bool IsOptLock { get; set; }
|
||||
|
||||
}
|
||||
public class UpdateNavOptions
|
||||
{
|
||||
|
@ -15,6 +15,7 @@ namespace SqlSugar
|
||||
bool UpdateParameterIsNull { get; set; }
|
||||
|
||||
int ExecuteCommandWithOptLock(bool isThrowError = false);
|
||||
int ExecuteCommandWithOptLockIF(bool? IsVersionValidation, bool? IsOptLock = null);
|
||||
Task<int> ExecuteCommandWithOptLockAsync(bool isThrowError = false);
|
||||
int ExecuteCommand();
|
||||
bool ExecuteCommandHasChange();
|
||||
|
Loading…
Reference in New Issue
Block a user