Aqui un par de ejemplitos con group y sum
var pcs = from a in db.Addresses
group a by a.PostalCode into g
select new {
PostalCode = g.Key,
Orders = (int?)g.Sum(addr => addr.SalesOrderHeaders_ShipTo.Count) ?? 0,
OrderValue = (decimal?)g.Sum(addr => addr.SalesOrderHeaders_ShipTo.Sum(o => o.SubTotal + o.Freight)) ?? 0m
};
--?======================
var processInfoByThreadCount =
from process in Process.GetProcesses()
group process by process.Threads.Count into g
orderby g.Key descending
select new { ThreadCount = g.Key,
ProcessCount = g.Count(),
ThreadSum = g.Sum( p => p.Threads.Count )
};
-- tomado de http://www.hookedonlinq.com/GroupByOperator.ashx --------
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment