Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouping a generic list via LINQ in VB.NET
    text
    copied!<p>I need to take a collection and group it via Linq but all the examples I've seen fail in some manner or other with some syntax difference that I can't quite lick.</p> <p>My collection:</p> <pre><code>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 </code></pre> <p>I need to turn this collection into a simple way to give this final outcome:</p> <pre><code>"5551110000@txt.att.net", "Alert, Document, Note" "jdoe@home.com", "Alert, Document, Note" </code></pre> <p>Here's the definition of the <code>ProcessAlert</code> class:</p> <pre><code>Public Class ProcessAlert Public LoanNumber As String Public EmailAddress As String Public AlertType As String Public AlertMethodID As Byte End Class </code></pre> <p>Thanks in advance,</p> <p>CD</p> <p>I've managed to convert to VB:</p> <pre><code> 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()))) </code></pre> <p>Now how do I add in to group by LoanNumber and Email Address so that my result is: "0000112367","jdoe@home.com", "Alert, Document, Note"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload