I'm kind of stuck with a problem that I'm having. Among others, I have this tables in my DB:
Product (int productId, ...otherProductInfo)
Customer (int customerId, ...otherCustomerInfo)
SoldToData ( int productId, int customerId)
I want to get top ten selling products using Entity Framework in MVC2. How can I do that?
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Following thekip's and Pr0fess0rX's advices, this is what I have done so far, and it seems to be working:
using (Entities db = new Entities())
{
var groupedProducts = (from p in db.Products
join s in db.SoldToData
on p.productId equals s.productId
group p by p.id
into ProductGroup
orderby ProductGroup.Count() descending
select ProductGroup).Take(10).ToList();
List<Products> products = new List<Products>();
products.AddRange(groupedProducts.Select(gp => gp.First()));
}
Is this the proper way?
using (Entities db = new Entities()) { var groupedProducts = (from p in db.Products join s in db.SoldToData on p.productId equals s.productId group p by p.id into ProductGroup orderby ProductGroup.Count() descending select ProductGroup).Take(10).ToList(); List<Products> products = new List<Products>(); products.AddRange(groupedProducts.Select(gp => gp.First())); }
Is this the proper way?