Browse Source

SqlQueryable functionality is optimized

pull/6/head
sunkaixuna 3 years ago
parent
commit
c60a4c3563
  1. 1
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 10
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs
  3. 4
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  4. 1
      Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmQueryBuilder.cs
  5. 1
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs
  6. 1
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleQueryBuilder.cs
  7. 1
      Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLQueryBuilder.cs
  8. 3
      Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerQueryBuilder.cs
  9. 1
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteQueryBuilder.cs

1
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -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)
{

10
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -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

4
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -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

1
Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmQueryBuilder.cs

@ -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)

1
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs

@ -61,6 +61,7 @@ namespace SqlSugar
result = sql.ToString();
}
this.OrderByValue = oldOrderValue;
result = GetSqlQuerySql(result);
return result;
}
private string ToCountSqlString()

1
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleQueryBuilder.cs

@ -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)

1
Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLQueryBuilder.cs

@ -61,6 +61,7 @@ namespace SqlSugar
result = sql.ToString();
}
this.OrderByValue = oldOrderValue;
result = GetSqlQuerySql(result);
return result;
}

3
Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerQueryBuilder.cs

@ -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;
@ -56,6 +56,7 @@ namespace SqlSugar
}
result += this.Offset;
}
result = GetSqlQuerySql(result);
return result;
}
}

1
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteQueryBuilder.cs

@ -61,6 +61,7 @@ namespace SqlSugar
result= sql.ToString();
}
this.OrderByValue = oldOrderBy;
result = GetSqlQuerySql(result);
return result;
}

Loading…
Cancel
Save