Gcobani Mkontwana

Gcobani Mkontwana

  • 1k
  • 1.2k
  • 108.9k

How to extract data correctly using linq sql in asp.net mvc 5?

Apr 26 2021 4:43 PM
  1. SELECT TOP (1000) [WeekId]  
  2.       ,[WeekNum]  
  3.       ,[Year]  
  4.       ,[CreatedDate]  
  5.       ,[CreatedBy]  
  6.       ,[ModifiedDate]  
  7.       ,[ModifiedBy]  
  8.       ,[InActive]  
  9.   FROM [ProductionManagement].[Schedule].[Week]  
  10.   where WeekNum = 53  
  11.   order by Year    
Hi team
 
I need some help and i have a problem the problem, the issue i have my excel data its duplicating a year, week column. e.g if data is available for 2021 its counting on week 2 as 2021 2, 2, 3. How do i fix this issue and must check if there is no data available for a specific year and week. 
  1. public IList GetExtractionViewModels()  
  2. {  
  3. var db = new ProductionManagementEntities();  
  4. var scheduleList = (from p in db.ProductionDays  
  5. from m in db.Models  
  6. from mx in db.Models  
  7. from mt in db.Models  
  8. from mv in db.Models  
  9. from wk in db.Models  
  10. join w in db.Weeks on p.WeekId equals w.WeekId  
  11. orderby w.Year descending, m.Name descending, p.ProductionDate descending, w.WeekNum descending, mt.Name descending, mx.Name descending, mv.Name descending  
  12. where (mx.InActive == true)  
  13. where (mt.InActive == false)  
  14. where(m.InActive == false)  
  15. where(mv.InActive == false)  
  16. where(w.WeekNum < 53)  
  17. where (mt.Name == "VW270")  
  18. where(mx.Name == "VW250")  
  19. where(m.Name == "VW270PA")  
  20. where(mv.Name == "VW250/2PA")  
  21. select new ExtractionViewModel  
  22. {  
  23. Year = w.Year,  
  24. Day = p.ProductionDate,  
  25. Week = w.WeekNum,  
  26. VW270 = mt.Name,  
  27. VW270PA = m.Name,  
  28. VW250 = mx.Name,  
  29. VW2502PA = mv.Name  
  30. }).ToList();  
  31. return scheduleList;  
  32. }  
  33.    
  34.     
  35. // model    
  36. public class ExtractionViewModel    
  37. {    
  38.     public string Year { getset; }   
  39.     public int Week { getset; }  
  40.     [DataType(DataType.Date)]    
  41.     public DateTime Day { getset; }  
  42.     public string VW250 { getset; }  
  43.     public string VW270 { getset; }   
  44.     public string VW2502PA { getset; }    
  45.     public int VW270PA { getset; }    
  46. }    
 
 
 

Answers (12)