goraz abz

goraz abz

  • NA
  • 2
  • 487

Query & SubQuery LINQ MVC

Apr 18 2018 12:33 AM
Hi,
Iam working on website which is about Fitnesse using Web API and I have page which is should display Session and in Every Session I should loop & display Session Items under Every Session, For ex in Program 1 ,have Two Session (Monday[loop SessionItem] & Saturday[loop SessionItem]) AND Program 2 ,have One Session (Wednesday[loop SessionItem])
 
BUT, When i Check Results in PostMan its like this :
 
Program 1 > Session (Monday,Saturday,Wednesday)
Program 2 > Session (Monday,Saturday,Wednesday)
 
But It Should like this :
 
Program 1 > Session (Monday [loop SessionItem], Saturday [loop SessionItem])
Program 2 > Session (Saturday [loop SessionItem])
 
This is My Code:
 
  1. [HttpGet]   
  2. public IHttpActionResult SessionInSessionItem(int id) {  
  3.   
  4. var data4 = db.Session.Select(m => new  
  5. {  
  6.   
  7. Session = m.Name,   
  8. SesseionItem = from y in db.Sessionjoin si in db.SessionItem on   
  9. y.ID equals si.SessionID   
  10.   
  11. where   
  12. si.SessionID == m.ID   
  13.   
  14. select new {  
  15. si.SessionID ,  
  16. y.Name,  
  17. si.Pause,  
  18. si.Reps¨  
  19.   
  20. }  
  21.   
  22. }).ToList();  
  23.   
  24. if (data4 == null) {  
  25.   
  26. return NotFound();   
  27. }   
  28.   
  29.   
  30. return Ok(data4); }  
Can someone please point me in right direction :)Thanks.