Get the sum of column using Entity Framework
<p>I want to implement the following SQL statement using entity framework:</p>

<pre><code>select coalesce(SUM(cdin_ActMortgageAmnt), 0) 
from CRM.dbo.CDIndex,CRM.dbo.company  
where comp_companyid = cdin_companyid 
  and comp_idcust like '%10319%' 
  and cdin_Deleted is null 
  and cdin_startunstufdate is not null 
  and cdin_Status = 'InProgress'
</code></pre>

<p>I tried to get the sum of <code>cdin_ActMortgageAmnt</code>:</p>

<pre><code>Company c = db.Companies.Find(750);  

var CGP = (from cd in db.CDIndexes  
           join com in db.Companies on cd.cdin_CompanyId equals com.Comp_CompanyId  
           where com.Comp_IdCust == c.Comp_IdCust &amp;&amp;  
                 cd.cdin_Deleted == null &amp;&amp;  
                 cd.cdin_startunstufdate == null &amp;&amp;  
                 cd.cdin_Status == "InProgress"  
           select new  
                 {  
                     act = cd.cdin_ActMortgageAmnt == null ? 0 : cd.cdin_ActMortgageAmnt 
                 }  
          );  

var query = CGP.Sum(x =&gt; x.act);  
lblSum.Text = query.ToString();  
</code></pre>

<p>But the query returns null while tracing...</p>