Language INtegrated Query; or LINQ, is a Microsoft .NET Framework component that adds native data querying capabilities to the .NET languages using syntax similar to SQL. LINQ is a part of the .NET Framework 3.5 and was released with the Visual Studio 2008 release on November 19, 2007.
Pro LINQ: Language Integrated Query in C# 2008 is written for the proficient C# developer who wants to learn this new technology. The author’s aim is to give you the information that matters, in a form that is usable. Instead of focusing on a complex demonstration application that cannot be put to practical use, he focuses on each of the examples as necessary. For example, when he is explaining concurrency conflicts, he has an example that creates a conflict so that you can step through it to see the conflict in action. Pro LINQ: Language Integrated Query in C# 2008 is 600 pages divided into 18 chapters segmented into 5 parts. I will cover this review based on the 5 parts.
Part 1, “Pro LINQ: Language Integrated Query in C# 2008″ begins by asking the question; “Did you just feel your world shift?” With the release of the .NET Framework 3.5, you should have. LINQ is going to change the way that developers query data. Soon, vendors will be adding “LINQ compatible” stickers to their products. Virtually any kind of data store would make a good candidate for supporting LINQ queries.
In this part you will be introduced to exactly what LINQ is, what it is not, and how it can be used. You will find some initial tips, and get an early taste of what the code looks like. Then you will get into C# 3.0′s language enhancements for LINQ. These include new object and collection initialization expressions, the ability to stub in static, sample or test data is much easier, as well as reducing the number of lines of code to create the data. Plus there is a lot more here to learn as well. One thing to note is that LINQ to Entities is not covered in this book because it is outside the core LINQ framework.
Part 2, “LINQ to Objects” looks at how you can use LINQ to work with objects; that is to work with any IEnumerable or IEnumerable<(Of <(T>)>) collection directly. If you have an array of integers and it needs to be sorted, you can now perform a LINQ query to order the results in the same way you would with a SQL query.
You will begin with learning what sequences are, the data type that represents them, and the impact of deferred query execution. It can work for or against you, so its understanding is of key importance. After you learn about the deferred operators, you will then learn about nondeferred operators. By the time you are done, you will have nearly 50 operators to choose from.
Part 3, “LINQ to XML” now moves on to XML. Here you will begin by seeing the standard methods for dealing with XML by using the W3C DOM XML API. Creating XML documents this way is a nightmare that is not only hard to read, it is even harder to support. In LINQ to XML, Microsoft not only supports queries, but it fixed a number of deficiencies in the XML API.
First the author begins by showing how to create XML hierarchies in a fraction of the code; 10 lines as opposed to 29 lines. He also shows you how to create, modify and traverse XML documents as well as performing queries on an XML object.
Next he covers how to query sequences of nodes or elements using the LINQ to XML operators, and then how to perform queries on XML trees and the standard query operators that can be mingled with LINQ to XML operators to perform powerful queries. Finally he explores some additional capabilities such as performing transformations with XSLT and without. He demonstrates how to validate an XML Document against a Schema as well as performing an XPath style query.
Part 4, “LINQ to DataSet” is next up, and here you are shown how to perform queries against any dataset that has been obtained using normal ADO.NET SQL queries. This provides a more dynamic database querying interface than LINQ to SQL since LINQ to SQL can only be performed on a Microsoft SQL server.
Next you will see how to work with typed datasets. This chapter begins by showing you how to make the most of LINQ to DataSet and then follows up with some real world examples. Since the reality is that your existing code uses datasets, by using LINQ to DataSets, you can retrofit your current code to take advantage of the new technology much quicker than rewriting to use LINQ to SQL.
Part 5, “LINQ to SQL” is an application programming interface for working with SQL Server databases. There is a disconnect between the programming language and the relational database. In the real world the data types that exist in the programming language differ from the database types. LINQ to SQL is Microsoft’s entry level LINQ-enabled Object-Relational Mapping (ORM) implementation for SQL Server.
In this section you will learn how to use LINQ to SQL to work with MS-SQL Servers, how to generate entity classes and external mapping files for the extended Northwind database as well as everything else that you need to know for working with LINQ to SQL.
As was said earlier, there should come a day when the term “LINQ compatible” will find its way to other products. It is now on MS-SQL. Will we see LINQ to Oracle?, LINQ to MySQL? Only time will tell, but as it sits today, LINQ to SQL works with Microsoft SQL Server. So until that day, there are many more options that are open to you.
Pro LINQ: Language Integrated Query in C# 2008 points out that while most people are focusing in on LINQ to SQL, they loose sight of the fact that LINQ has much more significance as a general purpose query language and that there are a multitude of ways to use it, and this book certainly shows you how.
I found that Pro LINQ: Language Integrated Query in C# 2008 really does cover LINQ in great detail, and the accompanying code is very usable and very well organized. It will be of benefit to anyone who wants to really learn LINQ and learn it in detail. The book itself is comprehensive enough to serve both as an introduction to the topic as well as a reference book for the future. If you want to get up and running with LINQ, I highly recommend this book.