I have a standard store schema with an InvoiceLine table that contains Products. I'd like to get a list of the top 5 products by sales as a List. What's the cleanest way to do that? This can't be the best way:
private List<Product> GetTopProducts(int count)
{
var topProducts = from invoiceLine in storeDB.InvoiceLines
group invoiceLine by invoiceLine.ProductId into grouping
orderby grouping.Count() descending
select new
{
Products = from Product in storeDB.Products
where grouping.Key == Product.ProductId
select Product
};
return topProducts.AsEnumerable().Cast<Product>().Take(count).ToList<Product>();
}