IEnumerable不能与类型参数一起使用

mas*_*oud 21 linq asp.net

我喜欢使用数据列表来显示用户名和注释以及用户名下面每个注释的附加内容.我有一个用户控件ReviewList来显示注释efiles.但我在这一行中有错误(s.tblDraft.Comments).我有错误:

The non-generic type 'System.Collections.IEnumerable' cannot be used with type arguments
Run Code Online (Sandbox Code Playgroud)

请帮忙解决问题.

private void Displayuser()
{
    var reviews =
      (from s in _DataContext.tblSends
       from u in _DataContext.Users

       where (s.DraftId == _Draftid) && (s.ToEmailId == u.ID)
       orderby u.Name
       select new
{
    userid = u.ID,
    username = u.Name,
    comments =s.tblDraft.Comments,
    w = s.tblDraft.Comments.SelectMany(q => q.CommentAttaches)

}).Distinct();

    DataList1.DataSource = reviews;
    DataList1.DataBind();

    var theReview = reviews.Single();

    DisplayReviews(theReview.comments, theReview.w);
}

private void DisplayReviews(IEnumerable<Comment> comments,
     IEnumerable<CommentAttach> w)
{
    ReviewList reviewList = (ReviewList)DataList1.FindControl("ReviewList1");
    reviewList.Comments = comments;
    reviewList.CommentAttachs = w;
    reviewList.DataBind();
}
Run Code Online (Sandbox Code Playgroud)

Joa*_*son 49

编译器看到的类型System.Collections.IEnumerable是非通用的IEnumerable.您导入了该命名空间,因此这是编译器认为您尝试使用的类型.

您尝试使用的类型是System.Collections.Generic.IEnumerable<T>.添加该命名空间的导入,应该编译.


Ari*_*ris 11

您需要添加命名空间的导入:

using System.Collections.Generic;
Run Code Online (Sandbox Code Playgroud)