using FreeSql;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
public static partial class FreeSqlSqlServerGlobalExtensions
{
///
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
///
///
///
///
public static string FormatSqlServer(this string that, params object[] args) => _sqlserverAdo.Addslashes(that, args);
static FreeSql.SqlServer.SqlServerAdo _sqlserverAdo = new FreeSql.SqlServer.SqlServerAdo();
///
/// SqlServer with(nolock) 查询
///
///
///
///
/// 多表查询时的锁规则
///
public static ISelect WithLock(this ISelect that, SqlServerLock lockType = SqlServerLock.NoLock, Dictionary 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);
///
/// 设置全局 SqlServer with(nolock) 查询
///
///
///
public static IFreeSql SetGlobalSelectWithLock(this IFreeSql that, SqlServerLock lockType, Dictionary rule)
{
var value = (lockType, rule);
_dicSetGlobalSelectWithLock.AddOrUpdate(that, value, (_, __) => value);
return that;
}
internal static ConcurrentDictionary)> _dicSetGlobalSelectWithLock = new ConcurrentDictionary)>();
}
public enum SqlServerLock
{
HoldLock, NoLock, PagLock, ReadCommitted, ReadPast, ReadUnCommitted, RepeaTableRead, RowLock, Serializable, TabLock, TabLockX, UpdLock, XLock
}