I have three models as below.
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Decimal Price { get; set; }
public bool Live { get; set; }
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
[ForeignKey(nameof(ParentCategory))]
public int? ParentId { get; set; }
public virtual Category ParentCat { get; set; }
public ICollection<Category> Children { get; set; }
}
public class CategoryProduct
{
public int Id { get; set; }
public int CatId { get; set; }
public int ProductId { get; set; }
}
I would need one or more linq to entities query to have a hierarchical map of the categories with the quantity of the related live products.
I give an example of the result I would like to obtain:
Computer (5)
Computer -> Windows (3)
Computer -> Windows -> lenovo (2)
Computer -> Windows -> HP (1)
Computer -> Apple (2)
Computer -> Apple -> Macbook air (2)
Queries should filter only categories that have products live true
Thank you