Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an example using nested foreach loops, I'm not sure how you would do this in a single string of linq statements, maybe with lots of selectmanys?</p> <pre><code>var transactions = new[]{ new{Category = "1", Form = "1", Title = "Trans1" }, new{Category = "1", Form = "1", Title = "Trans2" }, new{Category = "1", Form = "1", Title = "Trans3" }, new{Category = "1", Form = "2", Title = "Trans1" }, new{Category = "1", Form = "2", Title = "Trans2" }, new{Category = "1", Form = "2", Title = "Trans3" }, new{Category = "2", Form = "1", Title = "Trans1" }, new{Category = "2", Form = "1", Title = "Trans2" }, new{Category = "2", Form = "1", Title = "Trans3" }, new{Category = "1", Form = "3", Title = "Trans1" }, new{Category = "1", Form = "3", Title = "Trans2" }, new{Category = "1", Form = "3", Title = "Trans3" }, }; foreach(var byCategory in transactions.GroupBy(x =&gt; x.Category)) { Console.WriteLine(byCategory.Key); foreach(var byForm in byCategory.GroupBy(x =&gt; x.Form)) { Console.WriteLine("\t" + byForm.Key); foreach(var trans in byForm) { Console.WriteLine("\t\t" + trans.Title); } } } </code></pre> <p>Just because I was curious what it would look like I came up with the following, YOU SHOULD NOT USE THIS IN PRODUCTION CODE as it is ridiculous (if you do have a data structure like this it should be broken up into something like <code>Dictionary&lt;CategoryName, FormGroup&gt;</code> or something with meaningful types)</p> <pre><code>Dictionary&lt;string, Dictionary&lt;string, List&lt;string&gt;&gt;&gt; tooManyDictionaries = transactions .GroupBy(x =&gt; x.Category) .ToDictionary( catGroup =&gt; catGroup.Key, catGroup =&gt; catGroup .GroupBy(x =&gt; x.Form) .ToDictionary( formGroup =&gt; formGroup.Key, formGroup =&gt; formGroup.Select(x =&gt; x.Title).ToList())); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload