根据列对一组行进行分组

时间:2013-07-18 13:46:00

标签: c# linq

您好我有从我的数据库中获取数据的情况,它看起来像这样:

enter image description here

我首先使用Entity Framework数据库和一个存储过程来获取这些数据。这是我得到的模型:

public partial class GetELearningSessionsForStudent_Result
{
    public int LessonNumber { get; set; }
    public string LessonTitle { get; set; }
    public Nullable<int> Status { get; set; }
    public Nullable<System.DateTime> TargetDate { get; set; }
    public string EventTitle { get; set; }
}

现在我希望能够将LessonNumber分组并将其用作密钥,其中包含以下内容:

     KEY                                   Data
{LessonNumber AND LessonTitle} {Status , TargetDate , EventTitle}

我一直试图这样做几个小时,我觉得我很遗憾。 我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

这是你要找的吗?

listOfItems.GroupBy(key => new { key.LessonNumber, key.LessonTitle },
     data => new {data.Status, data.TargetDate, data.EventTitle});