tags:

views:

165

answers:

1

Hi all! I have to calculate the percentage in the group by clause. More in depth I need to calculate the percentage of ControlForms that have Status = 'False'. The Status is in the table checkResult.

var items = (from controlForm in dataContext.ControlForms
             join controlFormStatus in dataContext.ControlFormStatus on controlForm.FK_ControlFormStatus equals controlFormStatus.Id
             join docCheck in dataContext.DocumentChecks on controlForm.Id equals docCheck.FK_ControlForm
             join checkResult in dataContext.CheckResults on docCheck.FK_CheckResult equals checkResult.Id
             where controlForm.FK_ControlCycle.ToString().Equals(controlCycleId) & (
             controlFormStatus.Description.Equals(Constants.ControlFormStatusTestControlOwner)
             | controlFormStatus.Description.Equals(Constants.ControlFormStatusApprovalProcessOwner))
             group controlForm by new { controlForm.Id, controlForm.FK_ControlCycle, controlForm.FK_SampleNode, controlForm.FK_Control, /*FUNCTION*/} into ctrlForm
                         select new ControlFormReportPartialResults(ctrlForm.Key.Id, ctrlForm.Key.FK_ControlCycle, ctrlForm.Key.FK_SampleNode, ctrlForm.Key.FK_Control, ValueFunction));

Can anyone suggest me what I have to but istead of /FUNCTION/? Or if there is another way to solve the problem? Any help is really welcome!

Thanks in advance, Dario Zanelli

A: 

Replace "collection" with the appropriate variable containing the items you want to calculate the percentage for:

collection.Select(item => item.Status == false).Count() / collection.Count() * 100
Iravanchi