From e99644e40fc9d785ead7e0febbc6594ff74d3591 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Mon, 7 Nov 2022 11:59:29 +0800 Subject: [PATCH] update --- Query-Data.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Query-Data.md b/Query-Data.md index 9008f71..bd884b6 100644 --- a/Query-Data.md +++ b/Query-Data.md @@ -18,6 +18,59 @@ FreeSql has made great efforts in querying data, especially the functions such a - [《Sharding Tables and Database》](Sharding-Tables-and-Database) - [《Tenant》](Tenant) +## SqlServer WithLock、WithIndex + +```csharp +var list = fsql.Select() + .WithLock() + .Limit(1).ToList(); +//SELECT TOP 1 ... FROM [Region] a With(NoLock) + +var list = fsql.Select() + .WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait) + .Limit(1).ToList(); +//SELECT TOP 1 ... FROM [Region] a With(NoLock, NoWait) + +var list = fsql.Select() + .WithLock() + .WithIndex("idx_01") + .Limit(1).ToList(); +//SELECT TOP 1 ... FROM [Region] a With(index=idx_01, NoLock) +``` + +Multi-Tables Query: + +```csharp +var list = Select() + .InnerJoin((a, b) => a.x == b.xx) + .WithLock(SqlServerLock.NoLock, new Dictionary + { + [typeof(T2)] = false + }) + .WithIndex("idx_01", new Dictionary + { + [typeof(T2)] = "idx_02" + }) + .Limit(1).ToList(); +//SELECT TOP 1 .. +//FROM [Region] a With(index=idx_01, NoLock) +//INNER JOIN [T2] b With(index=idx_02) ON a.[x] = b.[xx] +`````` + +Global NoLock: + +```csharp +//All entities +fsql.SetGlobalSelectWithLock(SqlServerLock.NoLock, null); + +//Effective designation +fsql.SetGlobalSelectWithLock(SqlServerLock.NoLock, new Dictionary +{ + [typeof(Region)] = true, + [typeof(T2)] = true +}); +``` + ## Special introduction to WhereDynamicFilter [《高效理解 FreeSql WhereDynamicFilter,深入了解设计初衷》](https://www.cnblogs.com/FreeSql/p/16485310.html)