Cassie Mod

Cassie Mod

  • NA
  • 488
  • 71.2k

Invalid Column (CollectorName) when try to create for info

Feb 2 2016 11:35 AM
hi,
 
I've got the following question, maybe somebody knows how to fix it. I use a gridview to display data. one of the data items is the CollectorID. However i want to change the collectorID to Collector name.
But when i do that, it says it isn't a valid column ( wich is because the column doesn't exist in the database). So for now i commenced everything out.
However how do i get it fixed and is it possible to fix ? please let me know.
 
Controller:
  1. using Kendo.Mvc.Extensions;  
  2. using Kendo.Mvc.UI;  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Linq;  
  6. using System.Web.Mvc;  
  7. using System.Web.Util;  
  8. using TelerikMvcApp1.Models;  
  9.   
  10. namespace TelerikMvcApp1.Controllers  
  11. {  
  12.     public class HomeController : Controller  
  13.     {  
  14.         public ActionResult Index()  
  15.         {  
  16.             var programCollectorDataFilesStatus = new ProgramCollectorDataFilesStatus();  
  17.             //var collectorsContext = new CollectorsContext();    // used to show collectorName but not working
  18.             //var collectorsList = collectorsContext.Col.ToList();  // used to show collectorName but nog working
  19.   
  20.             using (CollectorStatusContext collectorStatusContext = new CollectorStatusContext())  
  21.             {  
  22.                 IEnumerable<CollectorStatus> collectorstatuslist = collectorStatusContext.Collectors.ToList();  
  23.                 List<CollectorStatus> dataObjects = new List<CollectorStatus>();  
  24.                 foreach (var workItem in collectorstatuslist)  
  25.                 {  
  26.                     dataObjects.Add(new CollectorStatus  
  27.                     {  
  28.                         ServiceRunning = workItem.ServiceRunning,  
  29.                         BatchCompleted = workItem.BatchCompleted,  
  30.                         BatchErrorID = workItem.BatchErrorID,  
  31.                         CollectorID = workItem.CollectorID,  
  32.                         LastBatchID = workItem.LastBatchID,  
  33.                         LastChecked = workItem.LastChecked,  
  34.                         LastStart = workItem.LastStart  
  35.                     });  
  36.                 }  
  37.                 foreach (var item in collectorstatuslist)  
  38.                 {  
  39.                     CollectorStatus col = new CollectorStatus();  
  40.                     col.CollectorID = item.CollectorID;  
  41.                     ViewBag.CollectorID = col.CollectorID;  
  42.                 }  
  43.                 programCollectorDataFilesStatus.CollectorStatus = collectorstatuslist;  
  44.             }  
  45.   
  46.             using (DataFilesStatusContext dataFilesStatusContext = new DataFilesStatusContext())  
  47.             {  
  48.                 IEnumerable<DataFilesStatus> datafilesstatuslist = dataFilesStatusContext.DataFiles.ToList();  // it gives an error that CollectorName isn't a valid column
  49.                 List<DataFilesStatus> dataObjects = new List<DataFilesStatus>();  
  50.                 foreach (var workItem in datafilesstatuslist)  
  51.                 {  
  52.                     dataObjects.Add(new DataFilesStatus  
  53.                     {  
  54.                         LastDataFileID = workItem.LastDataFileID,  
  55.                         DatFileName = workItem.DatFileName,  
  56.                         DataFileCompleted = workItem.DataFileCompleted,  
  57.                         DataFileErrorID = workItem.DataFileErrorID,  
  58.                         CollectorID = workItem.CollectorID,  
  59.                         //CollectorName = collectorsList.FirstOrDefault(co => co.CollectorID == workItem.CollectorID).CollectorName  
  60.                     });  
  61.                 }  
  62.                 programCollectorDataFilesStatus.DataFilesStatus = datafilesstatuslist;  
  63.             }  
  64.   
  65.             using (ProgramStatusContext programStatusContext = new ProgramStatusContext())  
  66.             {  
  67.                     IEnumerable<ProgramStatus> programstatuslist = programStatusContext.Stats.ToList();  
  68.                     List<ProgramStatus> dataObjects = new List<ProgramStatus>();  
  69.                     foreach (var workItem in programstatuslist)  
  70.                     {  
  71.                         dataObjects.Add(new ProgramStatus  
  72.                         {  
  73.                             ProgramName = workItem.ProgramName,  
  74.                             ProgramLastRun = workItem.ProgramLastRun,  
  75.                         });  
  76.                     }  
  77.                     programCollectorDataFilesStatus.ProgramStatus = programstatuslist;  
  78.                 }  
  79.                 return View(programCollectorDataFilesStatus);  
  80.             }  
  81.   
  82.   
  83.         public ActionResult About()  
  84.         {  
  85.             ViewBag.Message = "Your app description page.";  
  86.   
  87.             return View();  
  88.         }  
  89.   
  90.         public ActionResult Contact()  
  91.         {  
  92.             ViewBag.Message = "Your contact page.";  
  93.   
  94.             return View();  
  95.         }  
  96.   
  97.         public ActionResult ResultCollectors_Read([DataSourceRequest]DataSourceRequest request)  
  98.         {  
  99.             return Json(GetCollectors().ToDataSourceResult(request));  
  100.         }  
  101.   
  102.         public ActionResult ResultDatafiles_Read([DataSourceRequest]DataSourceRequest request)  
  103.         {  
  104.             return Json(GetDataFiles().ToDataSourceResult(request));  
  105.         }  
  106.   
  107.   
  108.         private static IEnumerable<CollectorStatus> GetCollectors()  
  109.         {  
  110.             var programCollectorDataFilesStatus = new ProgramCollectorDataFilesStatus();  
  111.   
  112.             using (CollectorStatusContext collectorStatusContext = new CollectorStatusContext())  
  113.             {  
  114.                 IEnumerable<CollectorStatus> collectorstatuslist = collectorStatusContext.Collectors.ToList();  
  115.                 List<CollectorStatus> dataObjects = new List<CollectorStatus>();  
  116.                 foreach (var workItem in collectorstatuslist)  
  117.                 {  
  118.                     dataObjects.Add(new CollectorStatus  
  119.                     {  
  120.                         ServiceRunning = workItem.ServiceRunning,  
  121.                         BatchCompleted = workItem.BatchCompleted,  
  122.                         BatchErrorID = workItem.BatchErrorID,  
  123.                         CollectorID = workItem.CollectorID,  
  124.                         LastBatchID = workItem.LastBatchID,  
  125.                         LastChecked = workItem.LastChecked,  
  126.                         LastStart = workItem.LastStart  
  127.                     });  
  128.                 }  
  129.                 programCollectorDataFilesStatus.CollectorStatus = collectorstatuslist;  
  130.                 return dataObjects;  
  131.             }  
  132.         }  
  133.   
  134.   
  135.         private static IEnumerable<DataFilesStatus> GetDataFiles()  
  136.         {  
  137.             var programCollectorDataFilesStatus = new ProgramCollectorDataFilesStatus();  
  138.   
  139.             using (DataFilesStatusContext dataFilesStatusContext = new DataFilesStatusContext())  
  140.             {  
  141.                 IEnumerable<DataFilesStatus> datafilesstatuslist = dataFilesStatusContext.DataFiles.ToList();  
  142.                 List<DataFilesStatus> dataObjects = new List<DataFilesStatus>();  
  143.                 foreach (var workItem in datafilesstatuslist)  
  144.                 {  
  145.                     dataObjects.Add(new DataFilesStatus  
  146.                     {  
  147.                         LastDataFileID = workItem.LastDataFileID,  
  148.                         DatFileName = workItem.DatFileName,  
  149.                         DataFileCompleted = workItem.DataFileCompleted,  
  150.                         DataFileErrorID = workItem.DataFileErrorID,  
  151.                         CollectorID = workItem.CollectorID  
  152.                     });  
  153.                 }  
  154.                 programCollectorDataFilesStatus.DataFilesStatus = datafilesstatuslist;  
  155.                 return dataObjects;  
  156.             }  
  157.         }  
  158.   
  159.   
  160.   
  161.     }  
  162. }  
 gridview:
 
  1. @using TelerikMvcApp1.Models  
  2. @model ProgramCollectorDataFilesStatus  
  3.   
  4. @(Html.Kendo().Grid<DataFilesStatus>()  
  5. .Name("DataFilesGrid")  
  6.   
  7. .Columns(columns =>  
  8. {  
  9.     columns.Bound(d => d.LastDataFileID);  
  10.     columns.Bound(d => d.DatFileName);  
  11.     columns.Bound(d => d.DataFileCompleted);  
  12.     columns.Bound(d => d.DataFileErrorID);  
  13.     //columns.Bound(d => d.CollectorName); // this doesn't work , invalid column 
  14.     columns.Bound(d => d.CollectorID);  
  15. })  
  16. .Filterable()  
  17. .Sortable()  
  18. .Groupable()  
  19. .Pageable(pageable => pageable  
  20.             .Refresh(true)  
  21.             .PageSizes(true)  
  22. )  
  23. .DataSource(dataSource => dataSource  
  24.                        .Ajax()  
  25.                        .Read(read => read.Action("ResultDatafiles_Read""Home"))  
  26.                        .PageSize(10)  
  27. )  
  28. )  
 Model:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel.DataAnnotations;  
  4. using System.ComponentModel.DataAnnotations.Schema;  
  5. using System.Data.Entity;  
  6. using System.Linq;  
  7. using System.Web;  
  8.   
  9. namespace TelerikMvcApp1.Models  
  10. {  
  11.     public class DataFilesStatus  
  12.     {  
  13.         [Key]  
  14.         [Column("LastDataFileID")]  
  15.         [Display(Name = "Last DataFile ID")]  
  16.         public int LastDataFileID { get; set; }  
  17.         [Column("DatFileName")]  
  18.         [Display(Name = "Filename")]  
  19.         public string DatFileName { get; set; }  
  20.         [Column("DataFileCompleted")]  
  21.         [Display(Name = "Completed")]  
  22.         public bool? DataFileCompleted { get; set; }  
  23.         [Column("DataFileErrorID")]  
  24.         [Display(Name = "Error ID")]  
  25.         public int? DataFileErrorID { get; set; }  
  26.         [Column("CollectorID")]  
  27.         [Display(Name = "Collector ID")]  
  28.         public int? CollectorID { get; set; }  
  29.   
  30.         //public string CollectorName { get; set; }   // this is not working !! ( not really exits but only used to get CollectorName instead of CollectorID  
  31.         //public IEnumerable<BatchErrors> BatchErrors { get; set; }  
  32.         //public IEnumerable<FileErrors> Fileerrors { get; set; }  
  33.     }  
  34.   
  35. }  
 

Answers (1)