Note that there are some explanatory texts on larger screens.

plurals
  1. POsimplify my groupby
    text
    copied!<p>hi i would like to return the group data back to the ui layer.</p> <p>here is how i want to do a simplify the groupby "GenerationDate" and return the data in List&lt;> back to UI gridview. i find it very troublesome as i got to do the forloop. Also in the UI layer i got to do another forloop for this simple groupby. Could you help to simplify it? </p> <pre><code>public List&lt;SalaryTracker&gt; GetSalaryTrackerOrderByGenerationDate(int tutorId) { List&lt;SalaryTracker&gt; salary = new List&lt;SalaryTracker&gt;(); using (leDataContext db = new leDataContext()) { try { var r = from s in db.SalaryTrackers where s.StaffId == 2 &amp;&amp; s.PaymentDate == null group s by s.GenerationDate into g where g.Count() &gt; 0 select new { date = g.Key, totalSalary = g.Sum(p =&gt; p.SalaryAmount) }; foreach (var rr in r) { SalaryTracker m = new SalaryTracker(); m.GenerationDate = rr.date; m.SalaryAmount = rr.totalSalary; salary.Add(m); } return salary; } catch (Exception ex) { Logger.Error(typeof(SalaryTracker), ex.ToString()); throw; } } } </code></pre> <p>--------------- GUI</p> <pre><code>totalCommissionsGroup = salary.GetSalaryTrackerOrderByGenerationDate(tutor.Id); IList&lt;SalaryTracker&gt; rr = ( totalCommissionsGroup.GroupBy(x =&gt; x.GenerationDate) .Select(g =&gt; new SalaryTracker { MonthId = g.Key.Month, MonthToPay = common.GetMonthName(Convert.ToInt16(g.Key), true), SalaryAmount = g.Sum(x =&gt; x.SalaryAmount) })).ToList&lt;SalaryTracker&gt;(); gvSalaryPayment.DataSource = rr; </code></pre> <p>i do this so that i can get the MonthToPay in string</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload