VB.NET

2011-06-27 6 views
0
にLINQを介して単一のデータセットから2つの値と連結することにより、一般的なリストをグルーピング

私のクラスの定義VB.NET

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", "[email protected]", "Alert", 2)) 
    a.Add(New ProcessAlert("0000112367", "[email protected]", "Document", 2)) 
    a.Add(New ProcessAlert("0000112367", "[email protected]", "Note", 2)) 
    a.Add(New ProcessAlert("0000112367", "[email protected]", "Alert", 1)) 
    a.Add(New ProcessAlert("0000112367", "[email protected]", "Document", 1)) 
    a.Add(New ProcessAlert("0000112367", "[email protected]", "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によるグループ化と、必要な値が得られます。 "[email protected]"、 "Alert、Document、Note" "[email protected]"、 "Alert、Document、 」

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","[email protected]", "Alert, Document, Note" 
    "0000112367","[email protected]", "Alert, Document, Note" 

私はグループに2つのフィールドを取得し、その後にAlertTypeオブジェクトの値を連結するにはどうすればよいです単一のフィールド???事前

答えて

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()) 
}