Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. var model = forumsDb.Categories
  2. .Select(c => new {c, c.Threads.Count})
  3. .ToList()
  4.  
  5. public class Category
  6. {
  7. public int id {get;set;}
  8. public ICollection<Thread> Threads { get; set; }
  9.  
  10. /***some properties***/
  11. [NotMapped]
  12. public int ThreadCount {get;set;}
  13. }
  14.  
  15. public class YourModel
  16. {
  17. public YourModel(Category c, int count)
  18. {
  19. C = c;
  20. Count = count;
  21. c.Threads.Count = count;
  22. }
  23.  
  24. public Category C { get; set; }
  25. public int Count { get; set; }
  26. }
  27.  
  28. var model = forumsDb.Categories
  29. .Select(c => new YourModel(c, c.Threads.Count))
  30. .ToList()
  31.  
  32. foreach(var entry in model)
  33. {
  34. entry.c.ThreadCount = entry.Count;
  35. }
  36.  
  37. var categories = model.Select(m => m.c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement