can't get group by to work with sum RRS feed

  • Question

  • Can anyone tell me how to translate this into linq?

    SELECT     SUM(TrainerShare) AS paymentamount, TrainerId, FirstName, LastName
    FROM         vwTrainerPayments
    GROUP BY TrainerShare, TrainerId, FirstName, LastName

    The closest I can get is below but it obviously doesn't give me the first and last name fields.

    from tp in VwTrainerPayments group tp by tp.TrainerId into p select new { p.Key, Total = p.Sum(pmnt => pmnt.TrainerShare)}


    Monday, February 2, 2009 8:11 PM


  • This seems to work well enough.

    var payments = from tp in tdc.vwTrainerPayments group tp by new { tp.TrainerId, tp.FirstName, tp.LastName } into p select new { p.Key, Total = p.Sum(pmnt => pmnt.TrainerShare)};

    Monday, February 2, 2009 8:53 PM