Linq: An Introduction

Another thing that I like about programming in VB.NET beyond Extensions is LINQ. LINQ is similar to SQL in structure - which is “a declarative programming paradigm that expresses the logic of a computation without describing its control flow.” So LINQ takes declarative paradigm and applies it to object oriented programming.

What’s so great about this? Well, it does slow the program down, but it speeds up the the programming process, puts the information in a form that is more descriptive (although that is no excuse not to thoroughly comment your code), and makes programming easier.

So, for the updating program for the time card I am working on, I put the updating version control document in an XML document.  The structure of the document is at the bottom of this post. To query this document using LINQ I have the following code:

'Get version number string from specified item ID.
Dim sNewVersion = _
        (From oItem In mXML...
        Where oItem.@id = sItemID).<Version>.Value

How simple is that? You can imagine as more complex situations arise how simple the declarative language makes it. Yes, there is the learning hurdle, but once you get over it, it makes working with data much easier to work with. You can even use LINQ with classes, arrays, etc. I’m just scratching the surface of how powerful LINQ truly is.

Wed Apr 11, 2012 | tags: linq code

comments powered by Disqus