SelectMany Three Levels Deep

前端 未结 3 1775
甜味超标
甜味超标 2021-02-02 12:18

I can flatten the results of a child collection within a collection with SelectMany:

 // a list of Foos, a Foo contains a List of Bars
 var source = new List<         


        
3条回答
  •  终归单人心
    2021-02-02 12:38

    var q = (
        from f in foo
        from b in f.Bars
        from w in b.Widgets
        select w.WidgetId
       ).ToList();
    

    Also note that if you want the unique list, you can do .Distinct().ToList() instead.

提交回复
热议问题