mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
SqlQueryable functionality is optimized
This commit is contained in:
parent
587d69d41d
commit
c60a4c3563
@ -2419,6 +2419,7 @@ namespace SqlSugar
|
||||
asyncQueryableBuilder.AsTables = this.Context.Utilities.TranslateCopy(this.QueryBuilder.AsTables);
|
||||
asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop;
|
||||
asyncQueryableBuilder.Offset = this.QueryBuilder.Offset;
|
||||
asyncQueryableBuilder.IsSqlQuery = this.QueryBuilder.IsSqlQuery;
|
||||
}
|
||||
protected int SetCacheTime(int cacheDurationInSeconds)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ namespace SqlSugar
|
||||
#region Splicing basic
|
||||
public List<string> IgnoreColumns { get; set; }
|
||||
public bool IsCount { get; set; }
|
||||
public bool IsSqlQuery { get; set; }
|
||||
public int? Skip { get; set; }
|
||||
public int ExternalPageIndex { get; set; }
|
||||
public int ExternalPageSize { get; set; }
|
||||
@ -475,6 +476,15 @@ namespace SqlSugar
|
||||
{
|
||||
return Regex.IsMatch(sql, @"AS \[\w+\.\w+\]");
|
||||
}
|
||||
public string GetSqlQuerySql(string result)
|
||||
{
|
||||
if (this.IsSqlQuery && (Skip == null && Take == null))
|
||||
{
|
||||
result = System.Text.RegularExpressions.Regex.Match(result, @"^SELECT t\.\* FROM \((.*)\) t $").Groups[1].Value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get SQL Partial
|
||||
|
@ -578,7 +578,9 @@ namespace SqlSugar
|
||||
public ISugarQueryable<T> SqlQueryable<T>(string sql) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
return this.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).With(SqlWith.Null).Select(sqlBuilder.GetDefaultShortName() + ".*");
|
||||
var result= this.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).With(SqlWith.Null).Select(sqlBuilder.GetDefaultShortName() + ".*");
|
||||
result.QueryBuilder.IsSqlQuery = true;
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -48,6 +48,7 @@ namespace SqlSugar
|
||||
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
|
||||
}
|
||||
this.OrderByValue = oldOrderBy;
|
||||
result = GetSqlQuerySql(result);
|
||||
return result;
|
||||
}
|
||||
public override string ToPageSql(string sql, int? take, int? skip, bool isExternal = false)
|
||||
|
@ -61,6 +61,7 @@ namespace SqlSugar
|
||||
result = sql.ToString();
|
||||
}
|
||||
this.OrderByValue = oldOrderValue;
|
||||
result = GetSqlQuerySql(result);
|
||||
return result;
|
||||
}
|
||||
private string ToCountSqlString()
|
||||
|
@ -51,6 +51,7 @@ namespace SqlSugar
|
||||
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
|
||||
}
|
||||
this.OrderByValue = oldOrderBy;
|
||||
result = GetSqlQuerySql(result);
|
||||
return result;
|
||||
}
|
||||
public override string ToPageSql(string sql, int? take, int? skip, bool isExternal = false)
|
||||
|
@ -61,6 +61,7 @@ namespace SqlSugar
|
||||
result = sql.ToString();
|
||||
}
|
||||
this.OrderByValue = oldOrderValue;
|
||||
result = GetSqlQuerySql(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace SqlSugar
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
var isFirst = (Skip == 0 || Skip == null) && Take == 1&&DisableTop==false;
|
||||
var isFirst = (Skip == 0 || Skip == null) && Take == 1 && DisableTop == false;
|
||||
var isRowNumber = (Skip != null || Take != null) && !isFirst;
|
||||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
||||
string groupByValue = GetGroupByString + HavingInfos;
|
||||
@ -48,14 +48,15 @@ namespace SqlSugar
|
||||
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
|
||||
}
|
||||
this.OrderByValue = oldOrderBy;
|
||||
if (!string.IsNullOrEmpty(this.Offset))
|
||||
if (!string.IsNullOrEmpty(this.Offset))
|
||||
{
|
||||
if (this.OrderByValue.IsNullOrEmpty())
|
||||
if (this.OrderByValue.IsNullOrEmpty())
|
||||
{
|
||||
result += " ORDER BY GETDATE() ";
|
||||
}
|
||||
result += this.Offset;
|
||||
}
|
||||
result = GetSqlQuerySql(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ namespace SqlSugar
|
||||
result= sql.ToString();
|
||||
}
|
||||
this.OrderByValue = oldOrderBy;
|
||||
result = GetSqlQuerySql(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user