Gcobani Mkontwana

Gcobani Mkontwana

  • 563
  • 1.9k
  • 411.6k

Formatting of excel data to correspond to your table records

Apr 28 2021 1:11 PM
Hi Team
 
I have a method that does linq in sql to retrieve data and currently it does. But the issue my records on excel when downloaded are duplicating and no logic if there is no records. When i ran query on the db records, year and weekNum i dont get but my mvc application is duplicating this and need some help.
  1. public IList<ExtractionViewModel> GetExtractionViewModels()    
  2. {    
  3.       int Count;      
  4.     var db = new ProductionManagementEntities();  
  5.     var scheduleList = (from p in db.ProductionDays                            
  6.                         from m in db.Models    
  7.                         from mx in db.Models    
  8.                         from mt in db.Models    
  9.                         from mv in db.Models    
  10.                         from wk in db.Models                         
  11.                         join w in db.Weeks on p.WeekId equals w.WeekId     
  12.                         orderby w.Year descending , m.Name descending, p.CreatedDate descending, w.WeekNum descending, mt.Name descending, mx.Name descending, mv.Name descending     
  13.                             
  14.                // Main problem is calling of these record to get correct data prior to the records when doing a sql query to the db. Yet no records logic cater for if there are not any(year, week)    
  15.                         where (mx.InActive == true)    
  16.                         where (mt.InActive == false)    
  17.                         where(m.InActive == false)    
  18.                         where(mv.InActive == false)                            
  19.                         where (mt.Name == "VW270")    
  20.                         where(mx.Name == "VW250")    
  21.                         where(m.Name == "VW270PA")    
  22.                         where(mv.Name == "VW250/2PA")   
  23.                         select new ExtractionViewModel    
  24.                         {  
  25.                             Year = w.Year,    
  26.                             Day = p.CreatedDate,    
  27.                             Week = w.WeekNum,    
  28.                             VW270 = mt.Name,    
  29.                             VW270PA = m.Name,    
  30.                             VW250 = mx.Name,    
  31.                             VW2502PA = mv.Name,   
  32.                         }).ToList();  
  33.     return scheduleList;    
  34. }   
  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    
  12.     
  13. SELECT TOP (1000) [ProductionDayId]    
  14.       ,[WeekId]    
  15.       ,[ProductionDate]    
  16.       ,[DayOfWeek]    
  17.       ,[CreatedDate]    
  18.       ,[CreatedBy]    
  19.       ,[ModifiedDate]    
  20.       ,[ModifiedBy]    
  21.       ,[InActive]    
  22.   FROM [ProductionManagement].[Schedule].[ProductionDay]    
  23.   Order by ProductionDate  

Answers (3)