본문 바로가기
카테고리 없음

수동 그룹핑

by keisoft 2025. 5. 20.

// items: IEnumerable<IDictionary<string, object>>
// groupKey 컬럼을 기준으로 그룹핑

var groups = new Dictionary<object, List<IDictionary<string, object>>>();

foreach (var row in items)
{
    // "groupKey"는 그룹핑할 컬럼명으로 바꿔주세요
    if (!row.TryGetValue("groupKey", out var key)) continue;

    if (!groups.TryGetValue(key, out var list))
    {
        list = new List<IDictionary<string, object>>();
        groups[key] = list;
    }
    list.Add(row);
}

// groups: 각 그룹별로 묶인 결과
// groups.Keys: 그룹키 목록
// groups.Values: 각 그룹에 해당하는 row 리스트