c# - difference between linq query on list and linq query in class method -
i have list of custom objects , querying them using next method:
class="lang-cs prettyprint-override">private double getsurveyorearliestattendencemipercentage(ilist<insurancejobdto> jobs, int workingdays, int year, int month) { var kpi = j in jobs j.earliestsurveydateoffered.hasvalue && j.earliestsurveydateoffered.value.year == year && j.earliestsurveydateoffered.value.month == month && (j.instructiontoearliestsurveydateoffered.value <= workingdays || !j.ispolicyholdersurveydatepreference.value) select j; double totalcount = kpi.count(); double withinslacount = kpi.count(x => x.instructiontoearliestsurveydateoffered.value <= workingdays); homecoming totalcount > 0 ? withinslacount / totalcount : 0; } i decided cleaner way produce same result might add together method custom object:
class="lang-cs prettyprint-override">public bool meetssurveyorearliestattendancecriteria(int year, int month, int workingdays) { homecoming (earlieststartdateoffered.hasvalue && earliestsurveydateoffered.value.year == year && earliestsurveydateoffered.value.month == month && (instructiontoearliestsurveydateoffered.value <= workingdays || !ispolicyholdersurveydatepreference.value)); } and alter original query following:
class="lang-cs prettyprint-override">private double getsurveyorearliestattendencemidays(ilist<insurancejobdto> jobs, int workingdays, int year, int month) { var kpi = j in jobs j.meetssurveyorearliestattendancecriteria(year, month, workingdays) select j; double totalcount = kpi.count(); double totalworkingdays = kpi.sum(x => x.instructiontoearliestsurveydateoffered.value); homecoming totalcount > 0 ? totalworkingdays / totalcount : 0; } this yields different result , don't know why?
looks you're calculating 2 different metrics:
double withinslacount = kpi.count(x => x.instructiontoearliestsurveydateoffered.value <= workingdays); versus:
double totalworkingdays = kpi.sum(x => x.instructiontoearliestsurveydateoffered.value); c# linq
No comments:
Post a Comment