LINQ,加入,分组依据和总和

LINQ,加入,分组依据和总和

问题描述:

在此VB.NET查询中,如何获得对新语句中字段的访问?

In this VB.NET query, how can I get access to the fields in the new statement?

Dim query =
    From t1 In tbl1
    Join t2 In tbl2 On t1.CAMPAIGNID Equals t2.CAMPAIGNID
    Group By t1.CAMPAIGNID Into Group
    Select New With {
     .id = CAMPAIGNID,
     .CALLS = Group.Sum(Function(a) t2.CALLS),
     .count = Group.Count(Function(a) t1.TERMCD = "Refused")
    }

您可以通过传入的参数a访问这些字段.参数a是您通过New With {...}

You can access the fields via the passed in parameter a. The parameter a is of the anonymous type you created via New With {...}

Dim query =
    From t1 In tbl1
    Join t2 In tbl2 On t1.CAMPAIGNID Equals t2.CAMPAIGNID
    Group By t1.CAMPAIGNID Into Group
    Select New With {
        .id = CAMPAIGNID,
        .CALLS = Group.Sum(Function(a) a.t2.CALLS),
        .count = Group.Count(Function(a) a.t1.TERMCD = "Refused")
    }