A linq join combined with a regex
- by Geert Beckx
Is it possible to combine these 2 queries or would this make my code too complex?
Also I think there should be a performance gain by combining these queries since I think in the near future my source table could be over 11000 records.
This is what i came up with so far :
Dim lit As LiteralControl
' check characters not in alphabet
Dim r As New Regex("^[^a-zA-Z]+")
Dim query = From o In source.ToTable _
Where r.IsMatch(o.Field(Of String)("nam"))
lit = New LiteralControl(String.Format("letter: {0}, count: {1}<br />", "0-9", query.Count))
plhAlpabetLinks.Controls.Add(lit)
Dim q = From l In "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToLower.ToCharArray _
Group Join o In source.ToTable _
On l Equals o.Field(Of String)("nam").ToLowerInvariant(0) Into g = Group _
Select l, g.Count
' iterate the alphabet to generate all the links.
For Each letter In q.AsEnumerable
lit = New LiteralControl(String.Format("letter: {0}, count: {1}<br />", letter.l, letter.Count))
plhAlpabetLinks.Controls.Add(lit)
Next
Kind regards, G.