O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

LINQ Query Performance

By the way, the demonstration in the previous section is a prime example of using query expression combinations. Look at the following example and consider what might happen:

Sub PerformanceTest()

    Console.WriteLine("run query:")
    Console.WriteLine("--------------------")

    Dim sw = Stopwatch.StartNew
    Dim resultList = From adrElement In adrList
                        Order By adrElement.LastName, adrElement.FirstName
                        Where adrElement.ID > 50 And adrElement.ID < 100 And
                                adrElement.LastName Like "L*"

    Dim aList = resultList.ToList
    sw.Stop()
    Console.WriteLine("The query required: " & sw.ElapsedMilliseconds.ToString &
                      " milliseconds.")
End Sub

First, all elements are sorted and then filtered. That’s silly, because if you filter the elements first, then there ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required