Browse Source

Navigation update optlock

pull/40/head
sunkaixuan 1 year ago
parent
commit
911574069b
  1. 4
      Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs
  2. 44
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs
  3. 12
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  4. 2
      Src/Asp.Net/SqlSugar/Entities/DeleteNavOptions.cs
  5. 1
      Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs

4
Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs

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

44
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs

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

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

@ -64,7 +64,17 @@ 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,如果是一对多操作请更新主表统一用主表验证");

2
Src/Asp.Net/SqlSugar/Entities/DeleteNavOptions.cs

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

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

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