none
cannot convert from System.Collections.Generic.List<> to System.Collections.Generic.IEnumerable<> RRS feed

  • Question

  • Error occured when trying to add qresult. Anyone can advise how to fix below error: cannot convert from System.Collections.Generic.List<> to System.Collections.Generic.IEnumerable<>

    
    
    public class SystemAccessList
    {
         public SystemAccess SystemAccess { get; set; }
    
         public List<SystemAccess> SystemAccessList { get; set; }
    
         SystemDbContext db;
    
     public void setDbContext(PALMSConfigDbContext _db)
        {
            db = _db;
        }
    
      public SystemAccessList GetAccessList(SystemAccessList systemAccessList)
      {
    
        var qresult = db.tbl_SystemAccessList
                .GroupBy(g => g.ClassID)
                .AsEnumerable().Select(c =>
                {
                    var rr = new ResultRow { Class = c.Key };
                    foreach (var r in db.tbl_SystemAccessList.GroupBy(gg => gg.StudentID))
                    {
                        rr.Student[r.Key] = "N";
                    }
                    foreach (var r in c.Where(w => w.ClassID == c.Key))
                    {
                        rr.Student[r.StudentID] = "Y";
                    }
                    return rr;
                }).ToList();
    
        systemAccessList.SystemAccessList.AddRange(qresult);
        return systemAccessList;
    }
    
    class ResultRow
    {
        public ResultRow()
        {
            Student = new Dictionary<string, string>();
        }
    
        public string Class { get; set; }
    
        public IDictionary<string, string> Student { get; set; }
    
        public string GetHeader()
        {
            return Student.Aggregate("Class", (current, s) => current + "|" + s.Key);
        }
    
        public string GetSolidRow()
        {
            return Student.Aggregate(Class, (current, s) => current + "|" + s.Value);
        }
        }
    
      public class SystemAccess
       {
           [Key]
           public int ID { get; set; }
           public string ClassID { get; set; }
           public string StudentID { get; set; }
       }

    Thursday, June 16, 2016 7:25 AM

All replies

  • Hi ooi_happiness,

    >>Error occured when trying to add qresult. Anyone can advise how to fix below error: cannot convert from System.Collections.Generic.List<> to System.Collections.Generic.IEnumerable<>

    Based on your code snippet, I try to reproduce your issue on side by using your code, Since the code is  not complete, I couldn't reproduce the issue. Could you please provide a complete code which would reproduce issue, such as class named SystemAccessList and tbl_SystemAccessList.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, June 17, 2016 3:15 AM
    Moderator
  • Hi cole, i just edit it with the full code. Please help see how to fix the issue. Thanks!
    Friday, June 17, 2016 3:30 AM
  • Hi ooi_happiness,

    I'm try to reproduce your issue by using your code snippet, I found some problems in your code.

    1. In class named SystemAccessList, you define a property named SystemAccessList (code as below), which has the same name with your class.

    public List<SystemAccess> SystemAccessList { get; set; }

    2. Based on you code, we know property SystemAccessList is a collection of SystemAccess. but the code below, you use AddRange method adding a collection of ResultRow.

    var qresult = db.tbl_SystemAccessList
                .GroupBy(g => g.ClassID)
                .AsEnumerable().Select(c =>
                {
                    var rr = new ResultRow { Class = c.Key };
                    foreach (var r in db.tbl_SystemAccessList.GroupBy(gg => gg.StudentID))
                    {
                        rr.Student[r.Key] = "N";
                    }
                    foreach (var r in c.Where(w => w.ClassID == c.Key))
                    {
                        rr.Student[r.StudentID] = "Y";
                    }
                    return rr;
                }).ToList();
    
        systemAccessList.SystemAccessList.AddRange(qresult);

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, July 10, 2016 6:36 AM
    Moderator