Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public dynamic List()
- {
- var categories = db.Categories.OrderByDescending(x => x.CreatedDateTime).Select(x => new
- {
- ID = x.ID,
- Name = x.Name,
- RootCategoryName = x.RootCategory.Name,
- ItemCount = x.Items.Count() // This line
- });
- return Json(categories, JsonRequestBehavior.AllowGet);
- }
- public class Item
- {
- public int ID { get; set; }
- public int CategoryID { get; set; } // Seems like here I've done everything correctly
- public Category Category { get; set; } // Seems like here I've done everything correctly
- [Required]
- public string Name { get; set; }
- public string Info { get; set; }
- public bool? IsAccessory { get; set; }
- public int? RootItemID { get; set; }
- public Item RootItem { get; set; }
- }
- public class Category
- {
- public int ID { get; set; }
- public int? RootCategoryID { get; set; }
- public Category RootCategory { get; set; }
- [Required]
- public string Name { get; set; }
- public string Info { get; set; }
- public IQueryable<Item> Items { get; set; } // Here also it seems that I've done relations correctly
- public DateTime CreatedDateTime { get; set; }
- public DateTime ModifiedDateTime { get; set; }
- }
Add Comment
Please, Sign In to add comment