Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouping a generic list by 2 values and concatenation from a single dataset via LINQ in VB.NET
    text
    copied!<p>Definition of my 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>A generic list that is representative of data returned from DB</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 managed this LINQ statement that will group by LoanNumber and EmailAddress but I can't get the AlertType to show up as a concatenated field of all 3 values</p> <pre><code> Dim res = Alerts.GroupBy(Function(g) New With {Key .A = g.LoanNumber, Key .B = g.EmailAddress}) </code></pre> <p>This code will give me a grouping by EmailAddress and the values I need of: "jdoe@home.com", "Alert, Document, Note" "5551110000@txt.att.net", "Alert, Document, Note"</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>But I cannot seem to get the statement give me a return that looks like this:</p> <pre><code> "0000112367","jdoe@home.com", "Alert, Document, Note" "0000112367","5551112222@txt.att.net", "Alert, Document, Note" </code></pre> <p>How do I get 2 fields to group and then concatenate the values of AlertType into a single field???</p> <p>Thanks in advance</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