mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Add Queryable.TranLock
This commit is contained in:
parent
df30a3c6e2
commit
32a0057668
@ -389,6 +389,27 @@ namespace SqlSugar
|
|||||||
_WhereClassByPrimaryKey(new List<T>() { data });
|
_WhereClassByPrimaryKey(new List<T>() { data });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public ISugarQueryable<T> TranLock(DbLockType LockType = DbLockType.Wait)
|
||||||
|
{
|
||||||
|
Check.ExceptionEasy(this.Context.Ado.Transaction == null, "need BeginTran", "需要事务才能使用TranLock");
|
||||||
|
Check.ExceptionEasy(this.QueryBuilder.IsSingle()==false, "TranLock, can only be used for single table query", "TranLock只能用在单表查询");
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
|
{
|
||||||
|
if (LockType == DbLockType.Wait)
|
||||||
|
{
|
||||||
|
this.With("UpdLock,RowLock");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.With("UpdLock,RowLock,NoWait");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.QueryBuilder.TranLock = (LockType == DbLockType.Error? " for update nowait" : " for update");
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public ISugarQueryable<T> WhereColumns(List<Dictionary<string, object>> list)
|
public ISugarQueryable<T> WhereColumns(List<Dictionary<string, object>> list)
|
||||||
{
|
{
|
||||||
List<IConditionalModel> conditionalModels = new List<IConditionalModel>();
|
List<IConditionalModel> conditionalModels = new List<IConditionalModel>();
|
||||||
@ -3323,6 +3344,7 @@ namespace SqlSugar
|
|||||||
_Size=it._Size
|
_Size=it._Size
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
asyncQueryableBuilder.TranLock = this.QueryBuilder.TranLock;
|
||||||
asyncQueryableBuilder.IsDisableMasterSlaveSeparation = this.QueryBuilder.IsDisableMasterSlaveSeparation;
|
asyncQueryableBuilder.IsDisableMasterSlaveSeparation = this.QueryBuilder.IsDisableMasterSlaveSeparation;
|
||||||
asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery;
|
asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery;
|
||||||
asyncQueryableBuilder.Includes = this.QueryBuilder.Includes;
|
asyncQueryableBuilder.Includes = this.QueryBuilder.Includes;
|
||||||
|
@ -33,6 +33,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Splicing basic
|
#region Splicing basic
|
||||||
|
public string TranLock { get; set; }
|
||||||
public bool IsDisableMasterSlaveSeparation { get; set; }
|
public bool IsDisableMasterSlaveSeparation { get; set; }
|
||||||
public bool IsQueryInQuery { get; set; }
|
public bool IsQueryInQuery { get; set; }
|
||||||
public List<object> Includes { get; set; }
|
public List<object> Includes { get; set; }
|
||||||
|
14
Src/Asp.Net/SqlSugar/Enum/DbLockType.cs
Normal file
14
Src/Asp.Net/SqlSugar/Enum/DbLockType.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public enum DbLockType
|
||||||
|
{
|
||||||
|
Wait=0,
|
||||||
|
Error=1
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,7 @@ namespace SqlSugar
|
|||||||
ISugarQueryable<T> WhereClassByPrimaryKey(List<T> list);
|
ISugarQueryable<T> WhereClassByPrimaryKey(List<T> list);
|
||||||
ISugarQueryable<T> WhereClassByPrimaryKey(T data) ;
|
ISugarQueryable<T> WhereClassByPrimaryKey(T data) ;
|
||||||
ISugarQueryable<T> WhereColumns(List<Dictionary<string, object>> columns);
|
ISugarQueryable<T> WhereColumns(List<Dictionary<string, object>> columns);
|
||||||
|
ISugarQueryable<T> TranLock(DbLockType LockType = DbLockType.Wait);
|
||||||
ISugarQueryable<T> Where(Expression<Func<T, bool>> expression);
|
ISugarQueryable<T> Where(Expression<Func<T, bool>> expression);
|
||||||
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
||||||
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);
|
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);
|
||||||
|
@ -66,6 +66,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return "-- No table";
|
return "-- No table";
|
||||||
}
|
}
|
||||||
|
if (TranLock != null)
|
||||||
|
{
|
||||||
|
result = result + TranLock;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private string ToCountSqlString()
|
private string ToCountSqlString()
|
||||||
|
@ -43,6 +43,10 @@ namespace SqlSugar
|
|||||||
result = this.Context.SqlQueryable<object>(result).Skip(Skip??0).Take(Take??0).ToSql().Key;
|
result = this.Context.SqlQueryable<object>(result).Skip(Skip??0).Take(Take??0).ToSql().Key;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (TranLock != null)
|
||||||
|
{
|
||||||
|
result = result + TranLock;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return "-- No table";
|
return "-- No table";
|
||||||
}
|
}
|
||||||
|
if (TranLock != null)
|
||||||
|
{
|
||||||
|
result = result + TranLock;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@
|
|||||||
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
|
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
|
||||||
<Compile Include="Entities\SugarAbMapping.cs" />
|
<Compile Include="Entities\SugarAbMapping.cs" />
|
||||||
<Compile Include="Entities\JoinMapper.cs" />
|
<Compile Include="Entities\JoinMapper.cs" />
|
||||||
|
<Compile Include="Enum\DbLockType.cs" />
|
||||||
<Compile Include="Enum\NavigatType.cs" />
|
<Compile Include="Enum\NavigatType.cs" />
|
||||||
<Compile Include="Enum\SugarActionType.cs" />
|
<Compile Include="Enum\SugarActionType.cs" />
|
||||||
<Compile Include="Entities\SugarConnection.cs" />
|
<Compile Include="Entities\SugarConnection.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user