开发者

Getting linq error with group

I am getting the following error when I add the linq grouping.

Error 5 'System.Linq.IGrouping' does not contain a definition for 'Description' and no extension method 'Description' accepting a first argument of type 'System.Linq.IGrouping' could be found (are you missing a using directive or an assembly reference?)

using (var db = new DataContext())
{
     var query = from emp in db.Employees
                               .Where( e=> e.IsDeleted == false && e.DivisionId == divisionId)
                 from rev in db.Reviews
                               .Where( r=开发者_JS百科> r.EmployeeID == emp.EmployeeId && r.IsDeleted == false && r.ReviewPeriodId == reviewPeriodId)
                               .DefaultIfEmpty()
                 from obj in db.Objectives
                               .Where( o=> o.ReviewId == rev.ReviewId && o.IsDeleted == false)
                               .DefaultIfEmpty()
                 from objps in db.ObjectiveProgressStatusLanguages
                                .Where( s=> s.ObjectiveProgressStatusId == obj.ObjectiveProgressStatusId && s.LanguageId == langueageId)
                                .DefaultIfEmpty()
                 group objps by new {objps.Description, objps.StatusId into opsgroup

                 select new
                 { 
                     Status = opsgroup.Description, 
                     StatusId = opsgroup.StatusId,
                     Count = opsgroup.Count()  
                 };
    return query.CopyToDataTable();


Those fields should be part of the Key. Try changing it to:

  select new {
        Status = opsgroup.Key.Description,
        StatusId = opsgroup.Key.StatusId,
        Count = opsgroup.Count()
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜