name total score John 202 Simeon 303 john 100 simeon 200 kennedy 100 kennedy 200 /*I have so many of those records on my database, i want to querry the record and view them in gridview but i want to group them i have this querry */ SchoolEntitycontext sdc = new SchoolEntitycontext(); var cdc = from c in sdc.records select new { c.RecordId, c.Name, c.Score }; if (cdc.Count() > 0) { Gridrecord.DataSource = cdc; Gridrecord.DataBind(); } //Using Entity framework to linq it works well to populate the record on a gridview... but i want to group them so that each name will come with the total score and not to be repeating them.. Like Example name total score John 302 Simeon 503 kennedy 300 thanks for your wonderful time..
var groupedCdc = sdc.records.GroupBy(c=>c.Name) .Select(g=>new {Name =g.Key, Score =g.Sum(x=>x.Score)}).ToList(); Gridrecord.DataSource = groupedCdc;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)