score:3

Accepted answer

You cannot define property names of anonymous types as strings:

I have defined two classes to get your info together:

internal class Entry
{
    public string SystemUser { get; set; }
    public string HostName { get; set; }
    public string DIMSUser { get; set; }
    public string EntryDetails { get; set; }
    public string AssetName { get; set; }
    public string EntryDate { get; set; }
    public string EntryTime { get; set; }
}

internal class UserEntryPerDateInfo
{
    public string DIMSUser { get; set; }
    public string EntryDate { get; set; }
    public IEnumerable<Entry> EntryList { get; set; }
}

Here you populate your data:

IEnumerable<Entry> dataList = from d in dataTableResults.AsEnumerable()
                              select new Entry
                                {
                                    SystemUser=d["SystemUser"],
                                    HostName=d["Host Name"],
                                    DIMSUser=d["DIMS User"],
                                    EntryDetails=d["Entry Details"],
                                    AssetName=d["Asset Name"],
                                    EntryDate=d["Entry Date"],
                                    EntryTime=d["Entry Time"],
                                };

Then you group by date and user and get them in another class:

IEnumerable<UserEntryPerDateInfo> result = from a in dataList
                                           group a by new {User = a.DIMSUser, EntryDate = a.EntryDate}
                                           into grouped
                                           select
                                           new UserEntryPerDateInfo
                                           {
                                               DIMSUser = grouped.Key.User,
                                               EntryDate = grouped.Key.EntryDate,
                                               EntryList = grouped
                                           };

Related Articles