Browse Source

Optimized code

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
2f3c868cba
  1. 11
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs
  2. 1
      Src/Asp.Net/SqlSugar/Interface/ISqlBuilder.cs
  3. 3
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs

11
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

@ -73,14 +73,19 @@ namespace SqlSugar
}
public virtual string GetPackTable(string sql, string shortName)
{
return UtilMethods.GetPackTable(sql,shortName);
return UtilMethods.GetPackTable(sql, shortName);
}
public virtual string GetDefaultShortName() {
public virtual string GetDefaultShortName()
{
return "t";
}
public virtual string GetUnionAllSql(List<string> sqlList)
{
return string.Join("UNION ALL \r\n", sqlList);
}
public virtual void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex)
{
UtilMethods.RepairReplicationParameters(ref appendSql,parameters,addIndex);
UtilMethods.RepairReplicationParameters(ref appendSql, parameters, addIndex);
}
#endregion

1
Src/Asp.Net/SqlSugar/Interface/ISqlBuilder.cs

@ -28,6 +28,7 @@ namespace SqlSugar
string GetNoTranslationColumnName(string name);
string GetPackTable(string sql,string shortName);
string GetDefaultShortName();
string GetUnionAllSql(List<string> sqlList);
void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex);
}
}

3
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -310,6 +310,7 @@ namespace SqlSugar
public virtual ISugarQueryable<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
{
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
int i = 1;
List<KeyValuePair<string, List<SugarParameter>>> allItems = new List<KeyValuePair<string, List<SugarParameter>>>();
@ -324,7 +325,7 @@ namespace SqlSugar
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, new List<SugarParameter>()));
i++;
}
var allSql = string.Join("UNION ALL \r\n", allItems.Select(it => it.Key));
var allSql = sqlBuilder.GetUnionAllSql(allItems.Select(it => it.Key).ToList());
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
var resulut = this.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable"));
resulut.AddParameters(allParameters);

Loading…
Cancel
Save