Use LINQ to group by one field, sum based on group AND store on Dictionary
<p>I am having a hard time to achieve a result likely because I'm misunderstanding sintax. Here the case:</p>

<p>I have a class that outputs a list. In this list there are two fields that I want specifically. they are ItemID (string) and TotalNet (string). There are other fields but I don't need to work with them at this point, but I do later at code.</p>

<p>The ItemID is the identifier of an Item, it is not unique in the list, so I must group it into one and account how many times this item appears. I achieved that with the following:</p>

<pre><code>Dictionary&lt;string, int&gt; dstLoops = list.Select(l =&gt; l.ItemID).ToList()
                .GroupBy(x =&gt; x).ToDictionary(g =&gt; g.Key, g =&gt; g.Count());
</code></pre>

<p>So I get my dictionary with the ItemID, now unique, with the total times that Item appears on my list. </p>

<p>The part that I am struggling to achieve is to sum the TotalNet of all the times the ItemID appears on the list. </p>

<p>I managed to get that using this:</p>

<pre><code>var APTotal = from i in list group i by i.ItemID into g select new
            { total = g.Key, totals = g.Sum(i =&gt;Convert.ToDecimal(i.TotalAmountPaid)) };
</code></pre>

<p>The problem is, it is not a dictionary, and later in the code that will be a headache... well... not much but I would like to avoid it, so I tried:</p>

<pre><code> Dictionary&lt;string, decimal&gt; liststotal = list.Select(l =&gt; l.ItemID).ToList().
                GroupBy(x =&gt; x).ToDictionary(g =&gt; g.Key, g =&gt; g.Sum(Convert.ToDecimal(item.TotalAmountPaid)));
</code></pre>

<p>Unfortunately it returns me that I cannot convert decimal to System.Func</p>

<p>I have tried some other solutions from this forum and other places, but they usually don't add values to the dictionary.</p>

<p>I can accept two scenarios as a solution:</p>

<ol>
<li>Exactly what I requested above, where I will get a
dictionary with all Items from my List grouped by
ItemID and sum of their respective item.TotalNet;</li>
</ol>

<p>FROM:</p>

<blockquote>
  <p>Item1, 10<p>
  Item2, 15<p>
  Item2, 15<p></p>
</blockquote>

<p>TO:</p>

<blockquote>
  <p>Item1, 10<p>
  Item2, 30</p>
</blockquote>

<p>OR:
 2. a var/decimal/whatever that returns me the TotalNet of the current
    ItemID iteration (I can use a foreach/for later on the code to
    achieve the result I am looking for). So to be clear, this TotalNet
    must be the sum of all TotalNets with the same ItemID from my list
    that I am iterating at the moment. Something like "I'am on ItemID 1,
    go and sum all the TotalNet of ItemID 1 from List".</p>

<p>Honestly... I would like help with the first option, for the sake of learning, but a solution is appreciated whatever the means (sacrificing children in name of an old god to get my output will not be marked as a solution...and possibly down voted). </p>