David Smith

David Smith

  • NA
  • 2k
  • 0

Linq to Sql Dictionary

Apr 13 2022 11:35 PM

Can someone help me come up with a robust way to write this below. I dont like the linq below.

 

   Dictionary<string, List<DetailRoot>> colorDataList = colorReporter.GetSiteData();

            var userSessionMetrics = (from DetailRoot o in colorDataList.First().Value
                                      group o by (o.ColorGuid, o.ColorId) into t
                                      select new
                                      {
                                          UniqueID = t.Key,
                                          TotalItemsPurchased = t.Select(x => x.Details.Select(y => y.EventType == "Purchase")).Sum(z => z.Count()),
                                          ColorPurchases = t.Select(x => x.Details.Select(y => y.EventType == "Purchase")).Count() > 0 ? 1 : 0,
                                          ColorItemsCheckouts = t.Select(x => x.Details.Select(y => y.EventType == "Checkout")).Sum(z => z.Count()),
                                          ColorCheckouts = t.Select(x => x.Details.Select(y => y.EventType == "Checkout")).Count() > 0 ? 1 : 0,
                                          TotalRevenue = t.Select(x => x.Details.Where(y => y.EventType == "Purchase").Sum(z => z.Revenue))
                                      }).ToList();


Answers (1)