How do I write a LINQ query that inverts the grouping of a hierarchical data source?

后端 未结 3 633
孤独总比滥情好
孤独总比滥情好 2021-02-10 22:57

How would one write a LINQ query which takes a hierarchical source data and transforms it so that the grouping is inverted?

Say I have a list of Topic objects each of wh

3条回答
  •  我寻月下人不归
    2021-02-10 23:43

    IDictionary> data;
    var n = data.SelectMany(x => x.Value.Select(y => new { Topic = x.Key, Tag = y }))
      .GroupBy(x => x.Tag, x => x.Topic);
    

提交回复
热议问题