Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74.4k

get the sum of column using Entity framwork

Dec 11 2016 6:51 AM
Hello
i want to implement the following SQL statement using entity framework:
 
  1. 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'  
i tried to get the sum of cdin_ActMortgageAmnt
 
  1. Company c = db.Companies.Find(750);  
  2.       var CGP = (from cd in db.CDIndexes  
  3.                  join com in db.Companies on cd.cdin_CompanyId equals com.Comp_CompanyId  
  4.                  where  
  5.                  com.Comp_IdCust == c.Comp_IdCust &&  
  6.                  cd.cdin_Deleted == null &&  
  7.                  cd.cdin_startunstufdate == null &&  
  8.                  cd.cdin_Status == "InProgress"  
  9.                  select new  
  10.                  {  
  11.                   act=cd.cdin_ActMortgageAmnt  
  12.   
  13.                  }  
  14.                );  
  15.       var query = CGP.Sum(x => x.act);  
  16.       lblSum.Text = query.ToString();  
but the query gives me null while tracing? 

Answers (3)