Use IGrouping to iterate through the groups made by the Linq group
public static Dictionary<string, List<Request>> SplitRequestsByHeader(List<Request> requests)
{
var ordRequests = new Dictionary<string, List<Request>>();
var groups =
from r in ordRequests
group r by string.Format("{0}{1}{2}{3}", r.DistrictId, r.CustomerId, r.UnitId, r.OrderType) into grp
orderby grp.Key
select grp;
//Note: instead of iterating, could convert directly to Dictionary
//ordRequests = groups.ToDictionary(group => group.Key, group => group.ToList());
//Iterate each order within each group
foreach (IGrouping<string, Request> group in groups)
{
List<Request> ordGroup = new List<Request>();
foreach (var r in group)
{
ordGroup.Add(r);
}
ordRequests.Add(group.Key, ordGroup);
}
return ordRequests;
}
No comments:
Post a Comment