mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 SqlServer ISelect.WithLock 扩展方法,实现 with(nolock) 查询;
- 增加 SqlServer IFreeSql.SetGlobalSelectWithLock 扩展方法,实现全局设置 with(nock) 查询; - 移除 Aop.ToList; - 移除 Aop.Where;
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
public static partial class FreeSqlGlobalExtensions
|
||||
using FreeSql;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@ -9,4 +14,35 @@
|
||||
/// <returns></returns>
|
||||
public static string FormatSqlServer(this string that, params object[] args) => _sqlserverAdo.Addslashes(that, args);
|
||||
static FreeSql.SqlServer.SqlServerAdo _sqlserverAdo = new FreeSql.SqlServer.SqlServerAdo();
|
||||
|
||||
/// <summary>
|
||||
/// SqlServer with(nolock) 查询
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="lockType"></param>
|
||||
/// <param name="rule">多表查询时的锁规则</param>
|
||||
/// <returns></returns>
|
||||
public static ISelect<T> WithLock<T>(this ISelect<T> that, SqlServerLock lockType = SqlServerLock.NoLock, Dictionary<Type, bool> rule = null) where T : class
|
||||
=> rule == null ?
|
||||
that.AsAlias((type, old) => $"{old} with({lockType.ToString()})") :
|
||||
that.AsAlias((type, old) => rule.TryGetValue(type, out var trybool) && trybool ? $"{old} with({lockType.ToString()})" : old);
|
||||
|
||||
/// <summary>
|
||||
/// 设置全局 SqlServer with(nolock) 查询
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="options"></param>
|
||||
public static IFreeSql SetGlobalSelectWithLock(this IFreeSql that, SqlServerLock lockType, Dictionary<Type, bool> rule)
|
||||
{
|
||||
var value = (lockType, rule);
|
||||
_dicSetGlobalSelectWithLock.AddOrUpdate(that, value, (_, __) => value);
|
||||
return that;
|
||||
}
|
||||
internal static ConcurrentDictionary<IFreeSql, (SqlServerLock, Dictionary<Type, bool>)> _dicSetGlobalSelectWithLock = new ConcurrentDictionary<IFreeSql, (SqlServerLock, Dictionary<Type, bool>)>();
|
||||
}
|
||||
|
||||
public enum SqlServerLock
|
||||
{
|
||||
HoldLock, NoLock, PagLock, ReadCommitted, ReadPast, ReadUnCommitted, RepeaTableRead, RowLock, Serializable, TabLock, TabLockX, UpdLock, XLock
|
||||
}
|
Reference in New Issue
Block a user