开发者

Linq Sum for Multiple Joins

Can someone help me out with the following Linq statement? I'm trying to get join 4 tables through Linq, group by the last table and sum a property of the first.

var payments = (
                from payment in db.Payments
                join payees in db.cmsMembers on payment.PayeeID equals payees.nodeId
                join payeeGroups in db.cmsMember2MemberGroups on payees.nodeId equals payeeGroups.Member
                join groups in db.umbracoNodes on payeeGroups.MemberGroup equals groups.id
                group groups by new {groups.text, payment} into grouped开发者_JAVA技巧Payments
                select new
                {
                    Group = groupedPayments.Key.text,
                    Count = groupedPayments.Count(),
                    Amount = groupedPayments.Sum(?)
                }
            ).ToList();

The issue I'm having is that the in the groupedPayments.Sum(..) call I'm only getting access to the "groups" object. This is fine for the Group name and count aspect but the SUM has to be performed on the payment.Amount property.


I've managed to resolve my issue. I hadn't realised that the object in the group declaration would become the actual object witin the resulting group item. By altering the original statement to the following:

group payment by groups into groupedPayments

it seems that each instance of groupedPayments.Key in the select statement now corresponds to the payment row which is what I required.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜