开发者

Getting linq error with group

开发者 https://www.devze.com 2022-12-19 15:13 出处:网络
I am getting the following error when I add the linq grouping. Error5\'System.Linq.IGrouping\' does not contain a definition for \'Description\' and no extension method \'Description\' accepting a f

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

精彩评论

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

关注公众号