Group by with select new array using linq
<p>I need help with a linq query</p>
<p>I have a table of Products with names, inventory and other fields. There can be &quot;repeated&quot; product names but with &quot;different inventory&quot;.</p>
<p>I need 3 things:</p>
<ol>
<li>Select all products and group them by name</li>
<li>In the SELECT, SUM the inventory field of the products that have the same name</li>
<li>The Select should be retrieved on an &quot;array&quot; because I will send it through JSON</li>
</ol>
<p>So for example if I have a product pen with inventory 1.</p>
<p>And then another product with same name &quot;pen&quot; but with inventory 3</p>
<p>Then my select have to give me just 1 row with name &quot;pen&quot; and inventory &quot;4&quot;</p>
<p>I used to have a query like this:</p>
<pre><code>        var result = (from c in Products
                      where c.Inventory != 0
                      select new[] {
                         Convert.ToString(i++),
                         c.Name,
                         c.Family,
                         c.Inventory});
</code></pre>
<p>It works but now I need to add the &quot;group by&quot; product name and also sum the inventory of each product with the same name but I don't know how</p>