LINQ: Using INNER JOIN, Group and SUM

前端 未结 3 1654
遇见更好的自我
遇见更好的自我 2020-11-30 04:46

I am trying to perform the following SQL using LINQ and the closest I got was doing cross joins and sum calculations. I know there has to be a better way to write it so I am

3条回答
  •  青春惊慌失措
    2020-11-30 05:28

    Below code is working for me :

                              var credit = (from bm in BulkMessage
                              join sms in SMS on bm.BulkMessageId equals sms.BulkMessageId
                              where bm.ProfileId == pid && bm.IsActive == true
                               group sms by sms.SMSCredit into g
    
                              select new { SMSCredits = g.Sum(s => s.SMSCredit) }).FirstOrDefault();
    

提交回复
热议问题