I'm in the process of doing a LINQ query of an object call Recipe
that need to be ordered by it's score. In the beginning, I have a IEnumberable
of type Recipe
(already filtered with the search criteria) called selectedRecipies
Then, with the help of my friend google, I have done this query using an anonymous type:
var finalQuery = ((from h in db.StarRatings
where selectedRecipies.Any(sr => sr.IDRecipe == h.IDRecipe)
group h by new { h.IDRecipe } into hh
select new
{
hh.Key.IDRecipe,
Score = hh.Sum(s => s.Score)
}).OrderByDescending(i => i.Score));
And I think it work... My problem is that for my view, I need it to be of type Recipe
and finalQuery
seems to be of type IEnumerable<'a>
where a
is the anonymous type...
How can I get a List<>
of type Recipe without disturbing the OrderByDescending?