E10 error on sum - Embedded statement cannot be a declaration or

Hi,

 

I have a  bpm where I’m looking  through the parttran table to see how many times a job has been received to stock  by summing  the field  ActTranQty  for  comparison against another value later in the code.   I used the Epicor 4GL converter to migrate existing 4GL code and after cleaning things up, the 4GL code doesn’t work the same as it did in E9. The qty returned by  “rcvqty “ is giving me wrong  values.  I believe it’s because of where that is in the loop and why it increases the value.   Anyway… I’m trying to sum the ActTranQty   field  to see if I get better results  but when I do, I get an error saying that the embedded statement cannot be a declaration or labeled statement .

 

Anybody have any suggestions?  Below is part of the code with my before and after.

 

 

 

 

foreach (var PartTran_iterator in (from PartTran_Row in Db.PartTran

                                       where ttPartTran_xRow.JobNum == PartTran_Row.JobNum && string.Compare(PartTran_Row.TranType ,"MFG-STK",true)==0

                                      select PartTran_Row))

 

Before                                                                                                                                                                 

 

                               

       PartTran = PartTran_iterator;

       if (PartTran != null)

 

                                                                                               

      rcvqty = rcvqty + PartTran.ActTranQty;

      ttPartTran_xRow["Number01"] = rcvqty;

     

 

 

After

 

                               

       PartTran = PartTran_iterator;

       if (PartTran != null)

 

       int total = PartTran.Sum(p => p.ActTranQty);                                              

       ttPartTran_xRow["Number01"] = total;

 

 

Error CS1023: Embedded statement cannot be a declaration or labeled statement

 

 

 

I have also tried:

 

ttPartTran_xRow["Number01"] = PartTran.Sum(p => p.ActTranQty);

 

But then I get error:

 

'Erp.Tables.PartTran' does not contain a definition for 'Sum' and no extension method 'Sum' accepting a first argument of type 'Erp.Tables.PartTran' could be found (are you missing a using directive or an assembly reference?)