Exemplo n.º 1
0
    private void ProcessGroup(SqlTableInfo info, SqlGroup group)
    {
      if (group == null) return;

      var cols = group.GetColumnNames().ToList();
      var toRemove = cols.Where(c => c.EndsWith("*")).ToArray();
      if (toRemove.Any(c => c == "*"))
      {
        var ctx = new SqlContext(group);
        cols.AddRange(ctx.Tables.Where(t => t.Columns != null).SelectMany(t => t.Columns));
        info.AdditionalColumns = ctx.Tables.Where(t => t.Columns == null && t.Name != null)
          .Concat(ctx.Tables.Where(t => t.AdditionalColumns != null).SelectMany(t => t.AdditionalColumns)).ToArray();
      }
      else if (cols.Any(c => c.EndsWith("*")))
      {
        var ctx = new SqlContext(group);
        var additional = new List<SqlTableInfo>();
        SqlTableInfo colInfo;
        foreach (var col in toRemove.Select(c => c.TrimEnd('.', '*')))
        {
          if (ctx.TryByName(col, out colInfo))
          {
            if (colInfo.Columns == null)
            {
              additional.Add(colInfo);
            }
            else
            {
              cols.AddRange(colInfo.Columns);
            }
          }
        }
        info.AdditionalColumns = additional;
      }

      foreach (var item in toRemove)
      {
        cols.Remove(item);
      }
      if (cols.Any())
        info.Columns = cols;
      return;
    }