Sie Ste

Sie Ste

  • NA
  • 196
  • 184.5k

C# using linq question

Sep 21 2012 11:49 AM


I am working in a C#  2010 application where I have written the following lines of linq to sql code:

int TotCount = 0;           
string[] PkgIDs = rptData.Transaction.Where(c =>c.Package_ID.StartsWith("rva") &&
                                c.Received_Date != null ).Select(c => c.Package_ID).ToArray();
            foreach (string PkgID in PkgIDs)
            {
                var eCnt =  rptData.Details.Where(c =>c.Package_ID == PkgID).Select(c =>c.TotalTrans);
                TotCount = Convert.ToInt32(eCnt);
            }


My problem line of code is:    var eCnt =  rptData.Details.Where(c =>c.Package_ID == PkgID).Select(c =>c.TotalTrans);

I want to be able to obtain the value contained in the c.TotalTrans field and place the value in the eCnt field.

When I am stepping through the code and go to the line right after the line I listed above, I only see the sql equivalent value. I want to see the value for c.TotalTrans in the eCnt field.

I know what I need now is to actually make the linq to sql statement actually execute. That would be similar to the 'ToArray()'
statement listed above. However, I do not know what to change in the statement to actually obtain  the value.

Thus can you tell me what else I need to add to this statement so that I get my desired result?

Answers (4)