score:3

Accepted answer

Try this, assuming your entities are db.FoodIAte and db.FoodInFridge (loving the table names!):

var food = (from fif in db.FoodInFridge
           join fia in db.FoodIAte on fif.Food equals fia.Food
           select new
                  {
                      Food = fif.Food,
                      Category = fif.Category,
                      Date = fia.Date
                  })
           .OrderByDescending(f => f.Date)
           .ToList()

That way you have the food in order of date eaten, most recent first. Then if you want the top three of them, you can do (make sure you check that the food list is longer/same size as the number you are taking though, otherwise it'll die!):

var topFood = food.Take(3).ToList();

Related Articles