Guest User

Untitled

a guest
Jan 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public dynamic List()
  2. {
  3. var categories = db.Categories.OrderByDescending(x => x.CreatedDateTime).Select(x => new
  4. {
  5. ID = x.ID,
  6. Name = x.Name,
  7. RootCategoryName = x.RootCategory.Name,
  8. ItemCount = x.Items.Count() // This line
  9. });
  10.  
  11. return Json(categories, JsonRequestBehavior.AllowGet);
  12. }
  13.  
  14. public class Item
  15. {
  16. public int ID { get; set; }
  17.  
  18. public int CategoryID { get; set; } // Seems like here I've done everything correctly
  19. public Category Category { get; set; } // Seems like here I've done everything correctly
  20.  
  21. [Required]
  22. public string Name { get; set; }
  23. public string Info { get; set; }
  24.  
  25. public bool? IsAccessory { get; set; }
  26. public int? RootItemID { get; set; }
  27. public Item RootItem { get; set; }
  28. }
  29.  
  30. public class Category
  31. {
  32. public int ID { get; set; }
  33.  
  34. public int? RootCategoryID { get; set; }
  35. public Category RootCategory { get; set; }
  36.  
  37. [Required]
  38. public string Name { get; set; }
  39. public string Info { get; set; }
  40.  
  41. public IQueryable<Item> Items { get; set; } // Here also it seems that I've done relations correctly
  42.  
  43. public DateTime CreatedDateTime { get; set; }
  44. public DateTime ModifiedDateTime { get; set; }
  45. }
Add Comment
Please, Sign In to add comment