WebDec 15, 2011 · "IGrouping group" is actually an IEnumerable with a key, so you either: iterate on the group or use group.ToList () to convert it to a List foreach (IGrouping group in groups) { var thisIsYourGroupKey = group.Key; List list = group.ToList (); // or use directly group.foreach } Share Improve this answer Follow Web1 Answer Sorted by: 44 That's pretty easy - just use the Sum extension method on the group. var groupedData = from b in dataTable.AsEnumerable () group b by b.Field ("chargetag") into g select new { ChargeTag = g.Key, Count = g.Count (), ChargeSum = g.Sum (x => x.Field ("charge")) };
C# Linq Group By on multiple columns - Stack Overflow
WebOct 1, 2008 · 7 Answers. using (DataContext dc = new DataContext ()) { var q = from t in dc.TableTests group t by t.SerialNumber into g select new { SerialNumber = g.Key, uid = (from t2 in g select t2.uid).Max () }; } I want to accept both as answers, but I guess I can't so I voted for both of you guys. Thanks a BUNCH!!! WebMay 20, 2016 · Using Query Syntax: var feeResult = (from fee in fee_list group fee by fee.Currency into groupResult select new { Currency = groupResult.Key, FinalFees = groupResult.Sum (f => f.FeesCustom > 0 ? f.FeesCustom : f.FeesNormal) }).ToList (); Share Improve this answer Follow answered May 20, 2016 at 6:24 Zein Makki 29.1k 6 50 60 … share chat txp
C# - LINQ GroupBy Examples - CSharp Academy
WebSep 15, 2024 · To add a project that contains a LINQ to SQL file. In Visual Studio, on the File menu, point to New and then click Project. Select Visual Basic Windows Forms Application as the project type. On the Project menu, click Add New Item. Select the LINQ to SQL Classes item template. Name the file northwind.dbml. Click Add. WebApr 11, 2024 · 1 - Use Linq Blog Site Updates - Grouping Query Blog Site Updates ... The first method in the previous post assumbled all of the data then used Linq queries to group one entity based upon a second enitty then sum number in each group for each second enity. The second method used in this post is a bit more esoteric in that it used a Sql … WebSep 15, 2024 · In a LINQ query, the from clause comes first in order to introduce the data source ( customers) and the range variable ( cust ). C#. //queryAllCustomers is an IEnumerable var queryAllCustomers = from cust in customers select cust; The range variable is like the iteration variable in a foreach loop except that no actual iteration ... share chat twentyfour