I read another excellent book on LINQ recently, called LINQ in Action, which provides some excellent coverage of the new language enhancements added for LINQ as well as the various flavors of LINQ. If you are looking for a single book to learn:
Implicity Typed Local Variables
Object and Collection Initializers
LINQ To Objects
LINQ To Xml
LINQ To SQL
you will enjoy reading LINQ in Action.
LINQ in Action starts out by teasing you with an introducion to each flavor of LINQ so that you have an idea as to what will be discussed in future chapters. Think of the initial sample code as the “Hello World” to get your brain in tune with what is to come and the gist of the technology. The introduction gets you craving for more.
The book then introduces you to the language features in VB 9.0 and C# 3.0 that have been added for LINQ. You get solid coverage of the language features as well as sample code in both VB and C#. It puts the features in perspective based on what we had in previous versions of the languages to give you a good reference point as to where we have come from and where we are going.
LINQ in Action then dives into the standard query operators so you can get a feel for querying across all flavors of LINQ, whether you want to query against in-memory objects, XML, or a database.
The book then jumps into LINQ to Objects, LINQ to XML, and LINQ to SQL. Good coverage of the features as well as practical advice about performance considerations. I enjoyed the pragmatic and objective nature of the advice mentioning the overhead that can occur with LINQ vs. other language options, and yet showing the amazing results one can achieve using a simple query that would take many lines of code to achieve otherwise.
The LINQ To SQL coverage was excellent. You get into all the cool features with regard to O/R Mapping as well as the dicey parts of transaction management, concurrency, and disconnected data. It goes into support for stored procedures, user-defined functions, and executing queries and commands using the LINQ To SQL API.
I avoided the LINQ To XML coverage as I generally avoid XML topics :), only to come back to it with a real-world problem and found the solution in the first 10 pages of the chapter. The book is not only a good read, but a great reference manual when you come across problems
The end of the book has some examples on extending LINQ, LINQ in every layer as well as the dilemma of how we deal with LINQ To SQL in the data access layer- do we go RAD or do we implement a properly encapsulated LINQ To SQL Data Access Layer per Ian Cooper’s excellent Architecting LINQ To SQL Applications Series?
As far as improvements to the book, I playfully mentioned to Jim Wooley at the Orlando Code Camp that his coverage of LINQ To SQL was excellent, but that he was teasing us with his coverage of LINQ TO SQL in the Data Access Layer. He started talking about architecture and encapsulating LINQ To SQL, but stayed at a very high level. Just like before when I felt I could use a 3rd book in the saga of Domain-Driven Design and Applying Domain-Driven Design and Patterns that filled in many of the gaps, I could use a solid book on implementing LINQ To SQL in the Data Access Layer. I am about 90% there, but the Repository Pattern abstraction is hurting my edge cases where I need to introduce better and seamless use of the DataLoadOptions, etc. This coverage is certainly out-of-scope for the book, but Jim got me excited when he brought up the subject
I highly recommend LINQ In Action, It is enjoyable to read as well as a good reference for your development.
by David Hayden