I am creating a function on my restaurant review website that gets the cuisine of the last review and then finds other reviews with same cuisine that have a higher average score. It then saves every restaurant id in a database. However I keep on receiving the error Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int'
on the line where r.id = samecuisine
.
Any help would be grateful.
var samecuisine = (from r in db.Reviews
where r.Cuisine == review.Cuisine
select r.id);
var pick = (from r in db.Reviews
where r.id = samecuisine
select r.score).Average();
var choices = (from r in db.Reviews
where r.score >= pick
select r.RestaurantId).ToList();
It's unclear why you'd want to get a review ID at all. You're only interested in the scores for those reviews, right? I suspect you actually want to take part of your first query and part of your second:
var averageScoreForCuisine = (from r in db.Reviews
where r.Cuisine == review.Cuisine
select r.score).Average();
Or to my mind more readably:
var averageScoreForCuisine = db.Reviews
.Where(r => r.Cuisine == review.Cuisine)
.Average(r => r.score);
See more on this question at Stackoverflow