C # LINQ group and counting issues
I have the following query that groups a bunch of printers and then calculates their idle times. What I would like to do is get the number of printers in each group. I'm not sure if I need to run two queries or can I do this in one?
Query:
var records = (from r in SharePoint.Records
group r by new
{
Printer = getValue(r.Values["ows_printer_id_x003a_Device"]),
} into g
select new
{
Printers = g.Key.Printer,
CurrentHours = g.Sum(x => getDownTime(x.Values["ows_Downtime"])),
// Total = g.Count()
//CTDHours = g.Sum(x => x.Field<int>("CurrentHours") + x.Field<int>("CTDHours"))
});
+3
source to share
1 answer
var records = (from r in SharePoint.Records
group r by new
{
Printer = getValue(r.Values["ows_printer_id_x003a_Device"]),
} into g
select new
{
Printers = g.Key.Printer,
CurrentHours = g.Sum(x => getDownTime(x.Values["ows_Downtime"])),
Total = g.Count()
});
Total = g.Count
must work.
I'm curious why you are using getValue()
here and I think that's where your problem might be. Doesn't work Printer = r.ows_printer_id_x003a_Device
? Have you checked the data in the "ows_printer_id_x003a_Device" element and does this part of the grouping query you want? Try using LinqPad to break it.
0
source to share