Thursday, July 2, 2009

Introduction to LINQ - Part1 (1 of many)

Introduction
.NET 3.5 has brought many new features into the world of .NET programming and put at the hands of developers some very powerful tools such as; full support for client and server based ASP .NET AJAX, WCF support, and the ability to target your development to a specific version of the .NET framework, just to name a few. This article will be focusing on one of the biggest enhancement to the .NET framework with version 3.5: LINQ.
What is LINQ?
LINQ is an acronym for Language Integrated Query. It is a component of the .NET framework and adds querying capabilities to the language. It was fully integrated into in the .NET framework 3.5 in November of 2007. LINQ enables developers to project and filter data in any type of enumerable data structure, including objects built from relation databases and XML. Using LINQ you can retrieve data from any of these data structures in the exact format needed without adding all of your filtering and formatting conditions inside a foreach loop, for instance.

Do I Need Special Software to use LINQ?
Yes and no. LINQ is fully integrated with Visual Studio 2008 and Visual Studio 2010, so if you are already using Visual Studio 2008 or 2010 then you don’t need to do anything except maybe add a reference to System.Data.Linq if you are going to be using a LINQ-to-SQL data layer. If you are using Visual Studio 2005 you can install the community preview 2006 which was released about 6 or 7 months before .NET 3.5 and Visual Studio 2008 was released. The CTP is old but still useful if you haven’t moved over to Visual Studio 2008 yet. The CTP can be found here:

http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&displaylang=en

so enough with the history lesson, let’s get down to business.

How do I use LINQ in my Code?
First let me mention that the code examples and accompanying project associated with this article were created using Visual Studio 2008 and C#. Configuring Visual Studio 2005 to use LINQ is beyond the scope of this article, but the LINQ queries and syntax will be the same regardless of the environment in which they are used. This article also assumes you have some very basic knowledge of .NET, OOP, and Visual Studio in general. With that out of the way, let’s get into the code.
First open and unzip the project source code (IntroductionToLINQ_ExampleProject.zip) into a folder on your hard drive and open up IntroductionToLINQ.sln. The only code file of interest in this solution is Program.cs.

Introduction to LINQ - Part1 Continued...
Final Version of the Project can be download from the final post in this series - "Introduction to LINQ - Part1 (final of many)"

To see all posts on "Introduction to LINQ - Part1" Click on link to your right that says it.
Please do comment the post after you read, Thank you and have a good LINQ.

No comments:

Post a Comment