Browse Source

Add Queryable.TranLock

pull/19/head
sunkaixuan 3 years ago
parent
commit
32a0057668
  1. 22
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 1
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs
  3. 14
      Src/Asp.Net/SqlSugar/Enum/DbLockType.cs
  4. 1
      Src/Asp.Net/SqlSugar/Interface/IQueryable.cs
  5. 4
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs
  6. 4
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleQueryBuilder.cs
  7. 4
      Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLQueryBuilder.cs
  8. 1
      Src/Asp.Net/SqlSugar/SqlSugar.csproj

22
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -389,6 +389,27 @@ namespace SqlSugar
_WhereClassByPrimaryKey(new List<T>() { data });
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)
{
List<IConditionalModel> conditionalModels = new List<IConditionalModel>();
@ -3323,6 +3344,7 @@ namespace SqlSugar
_Size=it._Size
}).ToList();
}
asyncQueryableBuilder.TranLock = this.QueryBuilder.TranLock;
asyncQueryableBuilder.IsDisableMasterSlaveSeparation = this.QueryBuilder.IsDisableMasterSlaveSeparation;
asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery;
asyncQueryableBuilder.Includes = this.QueryBuilder.Includes;

1
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -33,6 +33,7 @@ namespace SqlSugar
#endregion
#region Splicing basic
public string TranLock { get; set; }
public bool IsDisableMasterSlaveSeparation { get; set; }
public bool IsQueryInQuery { get; set; }
public List<object> Includes { get; set; }

14
Src/Asp.Net/SqlSugar/Enum/DbLockType.cs

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

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

@ -54,6 +54,7 @@ namespace SqlSugar
ISugarQueryable<T> WhereClassByPrimaryKey(List<T> list);
ISugarQueryable<T> WhereClassByPrimaryKey(T data) ;
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(string whereString, object parameters = null);
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);

4
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs

@ -66,6 +66,10 @@ namespace SqlSugar
{
return "-- No table";
}
if (TranLock != null)
{
result = result + TranLock;
}
return result;
}
private string ToCountSqlString()

4
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleQueryBuilder.cs

@ -43,6 +43,10 @@ namespace SqlSugar
result = this.Context.SqlQueryable<object>(result).Skip(Skip??0).Take(Take??0).ToSql().Key;
}
if (TranLock != null)
{
result = result + TranLock;
}
return result;
}

4
Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLQueryBuilder.cs

@ -66,6 +66,10 @@ namespace SqlSugar
{
return "-- No table";
}
if (TranLock != null)
{
result = result + TranLock;
}
return result;
}

1
Src/Asp.Net/SqlSugar/SqlSugar.csproj

@ -105,6 +105,7 @@
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
<Compile Include="Entities\SugarAbMapping.cs" />
<Compile Include="Entities\JoinMapper.cs" />
<Compile Include="Enum\DbLockType.cs" />
<Compile Include="Enum\NavigatType.cs" />
<Compile Include="Enum\SugarActionType.cs" />
<Compile Include="Entities\SugarConnection.cs" />

Loading…
Cancel
Save