0

我的班级的定义

    Public Class ProcessAlert
       Public LoanNumber As String
       Public EmailAddress As String
       Public AlertType As String
       Public AlertMethodID As Byte
    End Class

代表从 DB 返回的数据的通用列表

     Dim a As New List(Of ProcessAlert)

     a.Add(New ProcessAlert("0000112367", "5551110000@txt.att.net", "Alert", 2))
     a.Add(New ProcessAlert("0000112367", "5551110000@txt.att.net", "Document", 2))
     a.Add(New ProcessAlert("0000112367", "5551110000@txt.att.net", "Note", 2))
     a.Add(New ProcessAlert("0000112367", "jdoe@home.com", "Alert", 1))
     a.Add(New ProcessAlert("0000112367", "jdoe@home.com", "Document", 1))
     a.Add(New ProcessAlert("0000112367", "jdoe@home.com", "Note", 1))

     Return a

我管理了这个将按 LoanNumber 和 EmailAddress 分组的 LINQ 语句,但我无法让 AlertType 显示为所有 3 个值的串联字段

     Dim res = Alerts.GroupBy(Function(g) New With {Key .A = g.LoanNumber, Key .B = g.EmailAddress}) 

此代码将按 EmailAddress 和我需要的值进行分组:“jdoe@home.com”、“Alert、Document、Note”“5551110000@txt.att.net”、“Alert、Document、Note”

    Dim res = Alerts.GroupBy(Function(i) i.EmailAddress).Select(Function(g) New KeyValuePair(Of String, String)(g.Key, String.Join(",", g.Select(Function(x) x.AlertType).ToArray())))

但我似乎无法得到这样的声明给我一个回报:

    "0000112367","jdoe@home.com", "Alert, Document, Note"
    "0000112367","5551112222@txt.att.net", "Alert, Document, Note"

如何获得 2 个字段进行分组,然后将 AlertType 的值连接到一个字段中???

提前致谢

4

1 回答 1

0

您是否正在寻找这样的东西:

From _a In a
Group _a.AlertType By _a.LoanNumber, _a.EmailAddress Into Group
Select New With
{
    .LoanNumber = LoanNumber,
    .EmailAddress = EmailAddress,
    .AlertTypes = String.Join(", ", Group.ToArray())
}
于 2011-07-14T15:21:09.687 回答