Linq查询与group by没有结果

时间:2013-08-30 02:03:11

标签: c# linq entity-framework

IEnumerable<EFDBActivityActual> _tempList = 
    context.ActivityActual
           .Include(a => a.ExercisesActualList.Select(b => b.AerobicActual.IntensityFactor))
           .Include(a => a.ExercisesActualList.Select(b => b.ResistanceActual.IntensityFactor))
           .Include(a => a.ExercisesActualList.Select(b => b.ResistanceActual.ResistanceSetList))
           .Include(a => a.ActivityLocation)
           .Include(a => a.ActivityTemplate)
           .Where(a => a.QserID == session.UserID &&
                 (a.CreatedOn >= _fromDate && a.CreatedOn <= _toDate) &&
                 ((a.ExercisesActualList.Count() != 0) && a.StartTime != null));


var dx = from a in _tempList
             select new
             {
                 weeknumber = WeekNumber(a.CreatedOn),
                 activity = a
             };

    var g = from ax in dx
            group ax by ax.weeknumber
            into bx
            select bx;

有人可以帮我解决这里发生的事情,我真的不知道这个查询发生了什么。它总是会给我一个错误:*结果视图='KoolHealth.Server.dll'和'System.Web.dll'中都存在类型'&lt;&gt; f__AnonymousType1'*

第一个匿名查询会给我结果,但是在第二个有group by的情况下,它不会。

1 个答案:

答案 0 :(得分:0)

请试试这个:

var g = from ax in dx
        group ax by new { ax.weeknumber } into bx
        select new bx;