DJ메탈짱™의 Free Style

[ASP.NET] LINQ to SQL(group by, sum) 본문

일(job)/MS(Microsoft)

[ASP.NET] LINQ to SQL(group by, sum)

뽀&쏭 2015. 12. 4. 12:49

// LINQ query (SUM)

var tSum =

from p in db.TBSimulation    // from

where p.USERID == ""         // where절

        group p by new { p.GROUPID,p.USERID } into grouping  // group by

        select new // sum column

        {

                 grouping.Key,

                 Totalprice = grouping.Sum(p => p.RESULT)

};

            

        // sum 바인딩

        foreach (var grp in tSum)

        {

                this.lblTPROFIT.Text = grp.Totalprice.ToString();

        }