A linq join combined with a regex

Posted by Geert Beckx on Stack Overflow See other posts from Stack Overflow or by Geert Beckx
Published on 2010-04-21T15:21:10Z Indexed on 2010/04/21 15:23 UTC
Read the original article Hit count: 230

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about .NET