Accepted answer

It's not clear why you're using First() to start with. How about:

var grouped = linqQuery.GroupBy(f => f.OwnerId).ToList();

Now each entry in "grouped" is a grouping. You can now use:

foreach (var group in grouped)
    Console.WriteLine("OwnerId: {0}", group.Key);
    int leadCount = group.Count(c => c.LeadStatus == 100000000);
    // etc - do what whatever else you want with the group

    // Let's dump all the customer IDs...
    foreach (var entry in group)


It sounds like you want to use all the items in myGroup. By calling First() you're limiting yourself to the first item only.

You could write your query as follows:

var query = from f in linqQuery.ToList()
            group f by f.OwnerId into myGroup
            from item in myGroup
            select new
                OwnerName = item.OwnerName,
                OwnerId = item.OwnerId,
                LeadStatus = item.LeadStatus.ToString(),
                EmailedToRSM = item.EmailedToRSM,
                OrderCount = myGroup.Count()

However, note that by doing so you would be flattening the results.

Related Articles