Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ Error Invalid Column Name on Group by sum
    primarykey
    data
    text
    <p>For some reason, when using two sums on a group by, i run into the error "invalid column name 'id'. When i only do one sum, it works as expected.</p> <p>The following <strong>fails</strong> and throws the error:</p> <pre><code>from pd in PrDetails.Where(_pd =&gt; _pd.PrId == 46) group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs } into g select new { g.Key.ProgramFund, g.Key.CostCenter, g.Key.Wbs, CommittedTotal = g.Sum(_pd =&gt; _pd.PrDetailPrAmounts.Sum(_pa =&gt; _pa.CommittedAmount)), OverheadTotal = g.Sum(_pd =&gt; _pd.PrDetailPrAmounts.Sum(_pa =&gt; _pa.OverheadAmount)) } </code></pre> <p>However, the following <strong>does</strong> work fine:</p> <pre><code>from pd in PrDetails.Where(_pd =&gt; _pd.PrId == 46) group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs } into g select new { g.Key.ProgramFund, g.Key.CostCenter, g.Key.Wbs, CommittedTotal = g.Sum(_pd =&gt; _pd.PrDetailPrAmounts.Sum(_pa =&gt; _pa.CommittedAmount)) } </code></pre> <p><strong>And also</strong>, when I get the overhead total, instead of the committed total, it works great:</p> <pre><code>from pd in PrDetails.Where(_pd =&gt; _pd.PrId == 46) group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs } into g select new { g.Key.ProgramFund, g.Key.CostCenter, g.Key.Wbs, OverheadTotal = g.Sum(_pd =&gt; _pd.PrDetailPrAmounts.Sum(_pa =&gt; _pa.OverheadAmount)) } </code></pre> <p>Why can't i get the committed total and overhead total at the same time?</p> <p>I have our basic table structure below:</p> <h2>PrDetails</h2> <p>Id (int)<br> PrId (int)<br> ProgramFund (linq class)<br> ProjectDetail (linq class) </p> <h2>ProjectDetails</h2> <p>Id (int)<br> CostCenter (linq class)<br> Wbs (linq class) </p> <h2>PrAmounts</h2> <p>Id (int)<br> PrDetailId (int)<br> CommittedAmount (decimal)<br> OverheadAmount (decimal)</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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