Querying SQL with LINQ
I love writing code. I especially love writing code that supports a capability that may be new or difficult to implement. After a while, though, writing boilerplate code is dull, dull, dull. For example, fifteen years ago properties were a relatively new concept (at least, for languages like Delphi, Visual Basic, and C++). Properties were kind of cool. Properties are still useful today, but writing them isn't that much fun (~snooze~). Ten years ago, writing data access code was still pretty cool. Accessing a database was much cooler than writing to an ISAM file. Now? Snooze.
Okay, if you're a brand new programmer, maybe writing some of this boilerplate code is still challenging and pretty cool, but if you've been writing code for a while, probably not so much.
Now, a cool way to access data is by using LINQ to SQL. LINQ, short for Language Integrated Query, is a query language that's part of the .NET Framework, and you write it right in with your other code. LINQ to SQL is an extension that implements an IQueryProvider for SQL. This provider basically turns your LINQ queries into SQL queries seamlessly, so you worry more about objects and data, and less about the database.
Because I've worked with LINQ (at least conceptually) since the summer of 2006, LINQ to SQL seems pretty straightforward to me now. In this article, that's how I'll present LINQ to SQL: as something that you'll want to use and that really isn't very difficult to use at its core.