using System.Collections.Generic;
public static void Main()
var ords = new List<order>();
ords.Add(new order{guid = "aaa",parent="",ProductID="100",Description="Burger",Quantity=1,Total=2.00});
ords.Add(new order{guid = "bbb",parent="aaa",ProductID="800",Description="+ Bacon",Quantity=1,Total=0.70});
ords.Add(new order{guid = "ccc",parent="",ProductID="101",Description="Fries",Quantity=1,Total=1.80});
ords.Add(new order{guid = "ddd",parent="",ProductID="101",Description="Fries",Quantity=1,Total=1.80});
ords.Add(new order{guid = "eee",parent="",ProductID="101",Description="Fries",Quantity=1,Total=1.80});
ords.Add(new order{guid = "fff",parent="",ProductID="102",Description=" Large Fries",Quantity=1,Total=2.80});
ords.Add(new order{guid = "ggg",parent="",ProductID="100",Description="Burger",Quantity=1,Total=2.00});
ords.Add(new order{guid = "hhh",parent="ggg",ProductID="800",Description="+ Bacon",Quantity=1,Total=0.70});
ords.Add(new order{guid = "iii",parent="",ProductID="102",Description=" Large Fries",Quantity=1,Total=2.80});
var lst = ords.GroupBy(x => new
GuidIfHaveChildren = (ords.Any(x2 => x2.parent == x.guid) ? x.guid : ""),
parent = x.First().parent,
ProductID = x.Key.ProductID,
Desc = x.First().Description,
Quantity = x.Sum(p => p.Quantity),
Total = x.Sum(p => p.Total)
Console.WriteLine(ord.ProductID+" "+ord.Quantity+" "+ord.Total);
public string guid {get;set;}
public string parent {get;set;}
public string ProductID{get;set;}
public string Description{get;set;}
public double Quantity{get;set;}
public double Total{get;set;}