无法隐式转换类型System.Collections.Generic.List<>'到'System.Collections.Generic.List<>

时间:2015-01-05 10:13:16

标签: linq entity-framework asp.net-mvc-4 webgrid

我是MVC4的新手,我想实现WebGrid,在为model.activity检索数据时工作正常。为了澄清我正在组合两个表来获取数据。

这里显示的错误是这样的 无法将类型'System.Collections.Generic.List'隐式转换为'System.Collections.Generic.List

请帮我解决这个问题。提前谢谢

public class MyViewModel
{
    public List<Tbl_Activity> activity;
    public List<Tbl_Clarification> clarification;
}

  public class ClarificationEntities
{
    public int ClrNo { get; set; }
    public Nullable<int> DailyReportID { get; set; }
    public string ReportingMgrComment { get; set; }
    public Nullable<System.DateTime> CreatedOn { get; set; }
    public string StaffComment { get; set; }
    public Nullable<int> CreatedBy { get; set; }
    public string Name { get; set; }
}

我正在向模型添加数据以在WebGrid中显示

 MyViewModel model = new MyViewModel();
 model.activity = db.Tbl_Activity.Where(x => x.DailyReportID == driD).ToList();
 model.clarification = (from c in db.Tbl_Clarification
                        join u in db.Tbl_Users on c.CreatedBy equals u.CreatedBy
                        where c.DailyReportID == did
                        select new ClarificationEntities
                         {
                           ClrNo = c.ClrNo,     
                           ReportingMgrComment = c.ReportingMgrComment,
                           StaffComment = c.StaffComment,
                           DailyReportID=c.DailyReportID,
                           Name=u.Name
                          }).ToList();
  return View(model);

1 个答案:

答案 0 :(得分:2)

MyViewModel的{​​{1}}字段类型错误...

尝试以下代替

clarification