我有和SQL查询:
SELECT dbo.Course.courseID, dbo.Course.cricosCode, dbo.Course.courseName,
dbo.StudentPaymentPlan.totalAmount, SUM(dbo.StudentPaymentDetails.paidAmount) AS paidTotal
FROM dbo.StudentPaymentDetails
INNER JOIN dbo.StudentPaymentPlan ON dbo.StudentPaymentDetails.paymentPlanID = dbo.StudentPaymentPlan.paymentPlanID
INNER JOIN dbo.Application ON dbo.StudentPaymentPlan.applicationID = dbo.Application.ApplicationId
INNER JOIN dbo.Course ON dbo.Application.courseID = dbo.Course.courseID
GROUP BY dbo.Course.courseID, dbo.StudentPaymentPlan.totalAmount, dbo.Course.cricosCode, dbo.Course.courseName
在LINQ中它的等价物是什么?
答案 0 :(得分:0)
我写了这个写意,所以可能需要一些摆弄才能让它正常工作,但整体想法应该是正确的。
将来,MSDN通常会有很好的文档,这就是我写这篇文章的方式。特别是,我在join clause和group clause上使用了他们的文章。祝你好运!
from detail in dbo.StudentPaymentDetails
join plan in dbo.StudentPaymentPlan on detail.paymentPlanID equals plan.paymentPlanId
join application in dbo.Application on plan.applicationID equals application.ApplicationID
join course in dbo.Course on application.courseID equals course.courseID
select new {CourseID = course.courseID, CricosCode = course.cricosCode, CourseName = course.courseName, TotalAmount = plan.totalAmount, PaidTotal = detail.paidAmount.Sum()}
group entry by (entry.CourseID, entry.TotalAmount, entry.CricosCode, entry.CourseName)