Multi-table query AS (Tablename) automatic NOLOCK

This commit is contained in:
sunkaixuan 2022-06-07 14:25:18 +08:00
parent 6dbf35ce4f
commit 193ac3169d
3 changed files with 21 additions and 2 deletions

View File

@ -274,6 +274,15 @@ namespace OrmTest
.Where((o) => o.Id > 0)
.ToList();
var db = Db;
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings
{
IsWithNoLockQuery = true,
};
var sql13 = db.Queryable<Order>().AS("[ORDER]")
.LeftJoin<OrderItem>((o,i) => o.Id == i.OrderId).AS<OrderItem>("[ORDERDETAIL]")
.LeftJoin<Custom>((o, i, c) => c.Id == o.CustomId).AS<Custom>("[CUSTOM]")
.Select<ViewOrder>().ToList();
}
public class VUOrder
{

View File

@ -2421,7 +2421,14 @@ namespace SqlSugar
if (this.QueryBuilder.AsTables != null && this.QueryBuilder.AsTables.Count==1)
{
var tableinfo = this.QueryBuilder.AsTables.First();
if (this.Context.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockQuery == true)
{
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )";
}
else
{
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + ")";
}
this.QueryBuilder.SelectValue = this.QueryBuilder.TableShortName +".*";
}
}

View File

@ -675,9 +675,12 @@ namespace SqlSugar
result += (TableShortName + UtilConstants.Space);
}
if (this.TableWithString.HasValue() && this.TableWithString != SqlWith.Null)
{
if (!result.TrimStart().StartsWith("("))
{
result += TableWithString + UtilConstants.Space;
}
}
if (!this.IsSingle())
{
result += GetJoinValueString + UtilConstants.Space;