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> > >(); foreach (var item in queryables) { var sqlObj = item.ToSql(); string sql = sqlObj.Key; UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i); if (sqlObj.Value.IsValuable()) { allItems.Add(new KeyValuePair <string, List <SugarParameter> >(sql, sqlObj.Value)); } else { allItems.Add(new KeyValuePair <string, List <SugarParameter> >(sql, new List <SugarParameter>())); } i++; } 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); return(resulut.Select <T>("*")); }
public virtual string GetPackTable(string sql, string shortName) { return(UtilMethods.GetPackTable(sql, shortName)); }