I have a query in my controller that gets all the apps, and includes their average rating from another table
var apps = from a in db.Apps
let rating = a.Ratings.Average(r => r.Stars)
select new { App = a, Rating = rating == null ? 0 : rating };
Then I order them based on which filter is passed from home....no big deal....
switch (sortOrder)
{
case "Top desc":
apps = apps.OrderByDescending(a => a.Rating);
break;
case "Newest":
apps = apps.OrderBy(a => a.App.DateUpdated);
break;
case "Newest desc":
apps = apps.OrderByDescending(a => a.App.DateUpdated);
break;
default:
apps = apps.OrderBy(a => a.Rating);
break;
}
Then return it to the view
return View(apps.ToPagedList(pageIndex, pageSize));
However, on the home page I get an error stating I am passing the wrong type of model Item, I am passing {Model.App, System. Double} ( I assume because of the way my query adds the Rating Average......How can I still get a rating average, but send back the proper model item type. Thanks!