I want to fetch top 5 most popular product under specific category say computer.
This is my class file:
public partial class Category {
public int Id { get; set; }
public string Name { get; set; }
public int ParentCategoryId { get; set; } //reference to Id
public ICollection<Category> _subcategories;
}
public partial class ProductCategory {
public int Id { get; set; }
public int ProductId { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
public virtual Product Product { get; set; }
}
public partial class Product {
public int Id { get; set; }
public string Name { get; set; }
public int ProductViewcount { get; set; }//indicated how many times product has been viewed means most popular product.
}
Here a sample fiddle which contain records: http://www.sqlfiddle.com/#!3/20cba
Final output:
ProductId ProductName
1 hp
2 compaq
3 lenovo
Here problem is Computer is my main category and laptop is child category of Computer so when i say get top 5 Product of computer i want to retrieve child category records also like in fiddle i want to get all records of child category that is Laptop
I know this that I have to perform order by on ProductViewCount and get top 5 products.