Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda Max and Max and Max

Tags:

c#

lambda

Quick and probably easy Lambda question:

I have a restaurant with reviews. I want to query for the one with the:

  • Max(AverageRating)
  • And the Max(ReviewCount)
  • And the Max(NewestReviewDate)
  • And the Min(DistanceAway)

Something like this:

var _Result = AllRestaurants
    .Max(x => x.AverageRating)
    .AndMax(x => x.ReviewCount)
    .AndMax(x => x.NewestReviewDate)
    .AndMin(x => x.DistanceAway);

Now, I know that is pseudo code. But it describes it perfectly!

Of course, in multiple statements, this is simple.

Just wondering if this is possible in one statement without killing the readability.

Thank you in advance. I know some of you love the query questions!

like image 724
Jerry Nixon Avatar asked Aug 04 '26 21:08

Jerry Nixon


1 Answers

You can't have multiple maxes or mins, that doesn't make sense. You'll need some kind of heuristic like:

   .Max(x => x.AverageRating * x.ReviewCount - x.DaysSinceLastReview - x.DistanceAway)
like image 104
IngisKahn Avatar answered Aug 07 '26 14:08

IngisKahn