score:2

Accepted answer

What about this:

var range = myContext.PerformanceRanges
            .SingleOrDefault(e=>e.LowThreshold <= score && e.HighThreshold >= score)??
            PerformanceRanges.Single(
                                      e=>e.HighThreshold == PerformanceRanges
                                                            .Max(p=> p.HighThreshold)
                                    );

string evaluationText = range.Description;

The range query will select the element that matches with the Thereshold ranges, and if the value is greater (the first query will return null), it will select the greatest range.

score:1

What about this:

  string evaluationText = myContext.PerformanceRanges.Where
                    (e =>
                          (e.LowThreshold <= score
                          &&
                          e.HighThreshold >= score) || 
                         (e.HighThreshold == 
                            myContext.PerformanceRanges.Max (
                                  x => x.HighThreshold) 
                            && score > e.HighThreshold )
                    )
                    .Select(eval => eval.Description).First().ToString();

Related Articles