2012-06-18 2 views
0

Linq에서 엔티티의 백분율을 계산하는 데 도움이되는 팁이 있습니까?Linq to Entities Percentages

2 개의 결과를 반환하고 메모리에서 계산하는 것보다 효율적인 방법이 있어야한다고 생각합니다. 아마도 풋을 발명 적으로 사용하는 것일까?

편집


감사합니다 마크는 의견을 남겨주, 여기에 코드입니다,하지만 난이 두 데이터베이스 안타가 발생합니다 생각 : 당신이 엔티티에 LINQ를 사용하여 작성하는 경우

int passed = (from lpt in this.PushedLearnings.Select(pl => pl.LearningPlanTask) 
where lpt.OnlineCourseScores.Any(score => score.ActualScore >= ((lpt.LearningResource.PassMarkPercentage != (decimal?)null) ?lpt.LearningResource.PassMarkPercentage : 80)) 
select lpt).Count(); 

int total = (from lpt in this.PushedLearnings.Select(pl => pl.LearningPlanTask) 
select lpt).Count(); 

double percentage = passed * 100/total; 
+1

가지고있는 코드를 게시 할 수 있습니까? –

+0

Thanks @ MarkByers 코드 샘플이 나타났습니다. –

답변

2

귀하의 질의에 select x * 100.0/y 행을 따라이 표현식이 SQL로 변환되어 데이터베이스에서 실행됩니다. 그것은 효율적 일 것입니다.