データセットに対して計算を実行するカスタムメソッドがあります。
private int GetPercentages(int OriginalValue, int TotalValue)
{
var newValue = (int)Math.Round(((decimal)OriginalValue / (decimal)TotalValue) * 100);
return newValue;
}
LINQtoEntitiesクエリ内でこのメソッドを実行できるようにする必要があります。
var data = from SurveyResponseModel in db.SurveyResponseModels
group SurveyResponseModel by SurveyResponseModel.MemberId into resultCount
select new ResultsViewModel()
{
MemberId = resultCount.Key,
PatientFollowUpResult = db.SurveyResponseModels.Count(r => r.PatientFollowUp),
PatientFollowUpResultPct = GetPercentages(db.SurveyResponseModels.Count(r => r.PatientFollowUp),totalResponsesResult),
ChangeCodingPracticeResult = db.SurveyResponseModels.Count(r => r.ChangeCodingPractice),
};
クエリ内のさらに約20行でこれを実行する必要があるため、インラインで貼り付けるだけでは良いオプションとは思えません。SQL構文に変換する必要があることは理解していますが、このような他にできることはありますか?