Cannot implement type XYZ with a collection initializer because it does not implement 'System.Collections.IEnumerable' Cannot implement type XYZ with a collection initializer because it does not implement 'System.Collections.IEnumerable' asp.net asp.net

Cannot implement type XYZ with a collection initializer because it does not implement 'System.Collections.IEnumerable'


Make your fields public because they are not accessible as they are now.

public class CommentList{  public string ItemType;  public string Comment1;  public string Status1;  public string DiscussionBoardId;  public Guid CourseId;  public Guid CommentID;}

And explicity set them in your initializer.

select new CommentList{    ItemType = d.ItemType,    Comment1 = c.Comment1,    Status1 = s.Status1,    DiscussionBoardId = c.DiscussionBoardId,    CourseId = d.CourseId,    CommentID = c.CommentID};


Just a fuller follow-up to my comment. What you are trying to do is use object initialization, which requires you to name the properties. What it thinks you are trying is collection initialization

List<CommentList> query = from c in db.Comments                join s in db.Status on c.StatusId equals s.StatusId                join d in db.DiscussionBoards on c.DiscussionBoardId equals d.DiscussionBoardId                where d.CourseId == "CourseID"                orderby d.ItemType, d.DiscussionBoardId                select new CommentList                {                    ItemType = d.ItemType,                    Comment1 = c.Comment1,                    Status1= s.Status1,                    DiscussionBoardId = c.DiscussionBoardId,                    CourseId = d.CourseId,                    CommentId = c.CommentID                };


Your initialization is not correct. You need to assign values to explicit properties.

select new CommentList{    ItemType = d.ItemType,    Comment1 = c.Comment1,    Status1 = s.Status1,    DiscussionBoardId = c.DiscussionBoardId,    CourseId = d.CourseId,    CommentID = c.CommentID};