LINQ in Action - LINQ Book & News

  • LINQ in Action Second Edition is being printed!

    Our LINQ book

    LINQ in Action is doing well. We're all happy with the sales and all the reviews, on Amazon (5 stars on average) or on blogs.
    In fact, the book is doing so well that the publisher has to print a second edition! We didn't expect that it would happen so soon :-)

    We've updated the text where needed, according to the errata we've collected since the first edition was published, back in February. The new files are being sent to the printer right now.
    If you see something else that could be improved (for the third edition...), feel free to post a comment to the new errata page or in the forum.

    LINQ in Action can be found on Manning's website (with all the details and sample chapters), on Amazon.com, Amazon.co.uk, Amazon.ca, Amazon.fr, Amazon.jp, Amazon.de, BarnesAndNoble.com, and many more online and offline bookstores!

  • To var or not to var

    C# 3.0 and VB.NET 9.0 introduced implicit typing. When you use anonymous types, it's required. The rest of the time, it's mostly a judgment call to decide whether to use implicitly-typed local variables or not.
    An interesting discussion is going on about this on Jean-Paul S. Boodhoo's blog. See all the comments.
  • My TechDays 2007 sessions available in video

    The two sessions I co-presented during the Microsoft TechDays in February (and all the other sessions) were recorded, and the videos are now available. This is all in French, but I plan on recording soon an English version of my session about LINQ and C# 3. Stay tuned.


    Les deux sessions que j'ai co-présentées durant les Microsoft TechDays en février (et toutes les autres sessions) ont été enregistrées, et les vidéos sont maintenant disponibles.

  • LINQ in Action reviews and quotes

    Since our LINQ in Action book was published last month, we are lucky to receive a lot of nice feedback and comments. Steve, Jim, and I worked hard to make LINQ in Action a book that readers would enjoy. It's very encouraging to see what readers think about our work!
    I have collected a list of reviews and quotes.

    • "By far the best book available on LINQ"
    • "I have the LINQ books, and this is by far the best"
    • "One of the best overall tutorial texts on software development I have ever come across in 15 years"
    • "LINQ in Action ROCKS!"
    • "A pure pleasure to read"
    • "I'm having a hard time putting down LINQ in Action, to do my actual job!"
    • "One of the best .NET books ever written"
    • "Best book I've read in a while"
    • "I enjoy this book for its practical advice without trying to cover up any holes in the inaugural edition of LINQ"

    Read more

  • LINQ in Action book signing session in Paris

    A book signing session for LINQ in Action will take place at the Monde en Tique bookstore in Paris at the end of the month.


    Une session de dédicaces du livre LINQ in Action est prévue au Monde en Tique à Paris le samedi 29 mars. N'hésitez pas à passer nombreux entre 15h et 18h au 6 rue Maître Albert dans le 5ème, à deux pas de Notre-Dame, pour discuter du livre, de LINQ, de .NET ou même d'autre chose.

  • LINQ in Action is for VB developers too

    A frequent question we get about our LINQ book is whether it's been written for C# developers only. If you think so, you're making a mistake.

    We cover both C# and VB.NET in the book. This is one big difference with competing books. Even if not all code samples are in both languages all the time in the book, we make sure to demonstrate and explain the differences between both languages when it makes sense.

    In addition, to determine if this book is for you before buying it, you can take a look at all the resources we made available for free. This includes 3 free chapters and the source code. You can find them all on the book homepage.
    The complete source code for all the code samples in the book is available as a free download. All code files and projects are provided in C# and in VB.

    By the way, Jim is a VB.NET MVP. Do you think he'd been ok if we didn't cover VB in the book? Wink

  • Ever wanted to see LINQ in action, visually?

    It's not always easy to grasp and follow what's happening when a LINQ query is executed. Well, thanks to clever code by Jon Skeet, it's now possible to see LINQ queries execute in front of your eyes! At least LINQ to Objects queries that is.

    See this post about Visual LINQ in which Jon introduces the concept and the prototype implementation. You may want to watch the video or execute the code to instantly understand what it's all about.

  • Here it is: the LINQ in Action paper book!

    After two years of work on our LINQ book, and 10 days after the PDF ebook, here is the paper book!

     

    You can buy it directly from Manning's website to receive it immediately. It will become available on Amazon and in all the other bookstores shortly.

    The book already received a lot of very positive feedback! I'll share it with you soon.

  • LINQ in Action final PDF ebook available!

    The PDF of our LINQ book has been finalized! You can buy it on Manning's website for $27.50.

    There, you'll also find the following documents:

    • About This Book
    • Table of Contents
    • Preface
    • Foreword
    • Index

    We also have sample and bonus chapters awaiting you for free on the home page: 

    • Sample Chapter 1 (Introducing LINQ)
    • Sample Chapter 3 (LINQ building blocks)
    • Bonus Chapter 14 (Working with LINQ and DataSets)

    Finally, the same book home page contains links to the following resources

    • Author/Book Forum
    • Book Support Site
    • Source Code site
    • The Author's blogs

    In short, we offer you everything you need to become a LINQ champion :-)

    If you bought the ebook during the MEAP (Manning's Early Access Program) and haven't received the updated PDF, you should contact Manning directly.

    The paper book is just around the corner now. It's expected for January 31st. The earliest place for people to buy the book will be from Manning's website. The books should then arrive in bookstores and Amazon shortly after. Of course, you can already pre-order the paper book from these places.

  • LINQ in Action preface

    Here is the preface I wrote for LINQ in Action:

    I chose software development as the way to make a living mainly because it’s a technology that is constantly evolving. There’s always something new to learn. No chance of getting bored in this line of work! In addition to learning, I also enjoy teaching software development. Writing LINQ in Action was a good opportunity to both learn and teach at the same time.

    When we started writing this book, LINQ was still an early prototype. We followed its evolution as it was taking shape. There was a lot to discover and a lot to understand. This is part of a software developer’s everyday job. We have to stay up-to-date with the technologies we use and learn new ones as they come out. The software development environment is evolving at an increasingly fast pace, and I don’t see any signs that that’s going to change.

    .NET is a fast-moving environment. Over the last couple of years, we’ve seen two major releases of the .NET Framework, and several companion technologies have appeared: Windows Presentation Foundation, Windows Communication Foundation, Windows Workflow Foundation, ASP.NET AJAX, Silverlight, and LINQ have joined our developer toolbox. Another trend in .NET is the multiplication of programming languages. F#, which will receive the same support as C# or VB.NET in Visual Studio, introduces functional programming in .NET. Dynamic languages, such as Python and Ruby, are going to be supported by the .NET Dynamic Language Runtime.

    In coming years, we’ll have to deal with more programming languages than the ones we currently master. An advantage of C#, Visual Basic, and the other .NET languages is that they are constantly adapting. C# and VB.NET have been improved in their latest versions to offer support for language-integrated querying through LINQ.

    In addition to offering novel approaches to deal with data, LINQ represents a shift toward declarative and functional programming. When people ask me for reasons to learn LINQ, I tell them that they should learn it in order to be able to use it with XML, relational data, or in-memory collections, but above all to be able to start using declarative programming, deferred execution, and lambda expressions.

    Start learning LINQ now! When you do, you’ll not only learn how to use this new technology, but you’ll also discover where programming is heading. One of our main goals with LINQ in Action was to help you fully comprehend the new approaches associated with LINQ.

    Fabrice Marguerie

  • Query syntax vs. Method syntax

    In the official LINQ forum, someone asked whether it's better to use query syntax (query expression) or method syntax (dot notation).

    My answer is that it's mostly a matter of tastes and it depends on the query.
    If I'm writing a query that uses many query operators that aren't supported by the query syntax, then I use the method syntax. Mixing the two syntaxes in one single query can quickly make it hard to read, with all the parentheses.
    If I'm writing a query that consists of only one operation, then I use the method syntax as well.
    In other cases, the query syntax has advantages, like the ability to use "range" variables. The ones defined in from clauses. If you use the method syntax, then you have to redeclare the variables in each lambda expression passed as a parameter to a query operator.

    Let's consider the following example:

    from person in persons
    where person.Age > 12
    orderby person.LastName
    select person.LastName;

    Here, person is declared once and used in the where, orderby, and select clauses.
    If you write the same query using the method syntax, you have to "redeclare" person each time in the lambda expressions:

    persons
      .Where(person => person.Age > 12)
      .OrderBy(person => person.LastName)
      .Select(person => person.LastName);

    Another advantage of the query syntax is the ability to use let clauses. This is really useful in complex queries or simply to avoid performing the same operation several times in a query, by storing temporary results in a variable.
    Here is a sample query expression with a let clause:

    from person in persons
    let name = person.FirstName+person.LastName
    select new { Name = name, Phones = person.Phones.Count() }

    To reproduce the same using the method syntax, you have to write the following:

    persons
      .Select(person => new { person = person, name = person.FirstName+person.LastName })
      .Select(x => new { Name = x.name, Phones = x.person.Phones.Count() });

    Not so easy to read, don't you think? This is what the compiler generates when it encounters the above query expression, by the way.

    There are other advantages to each syntax, but the ones listed above are already enough to decide which one to use in most cases.

  • Getting really close now

    Book sent to the printer! Yeah!
  • LINQ sessions during TechDays France 2008

    From February 11 to 13 will take place the Microsoft TechDays France 2008. It will be the main Microsoft event of the year in France, with no less than 280 sessions.

    LINQ will be one of the major subjects covered this year: seven sessions will be related to LINQ. I'll be presenting two of them. The first one will be an introduction to LINQ. The second one will cover the ADO.NET Entity Framework and LINQ. You can learn more about my sessions on my blog.

    See you in paris next month!

     

  • Randomizing LINQ to SQL queries

    Yesterday, a developer asked in the LINQ in Action forum and in Microsoft's official LINQ forum how to write a LINQ to SQL query that would return random records from the database.

    It's not something built-in. There is no Random query operator provided by Microsoft. In addition, it can't be done simply by using the System.Random class, because everything in a LINQ to SQL query must be translatable to SQL.

    Jim replied with several options:

    • Use a pass-through query to get the results
    • Use a view to return the ID of the record from tblImages from your subselect and map to that view. Then use a LINQ query to join the tblProperties through the Randomize view and then to the tblImages
    • Use a scalar TSQL Function to get a random picture and include that in your LINQ query.
    • Use a stored procedure to return the results.

    As Jim points out, we discuss consuming pass-through queries, functions and stored procedures in chapter 8 of LINQ in Action.

    Let's detail the solution that uses a SQL user-defined function. The most common way to sort records randomly is to use the NEWID SQL Server function. This is what this solution uses.

    First, create the following view:

    CREATE VIEW RandomView
    AS
    SELECT NEWID() As ID

    Then create the following function that uses the view:

    CREATE FUNCTION GetNewId
    (
    )
    RETURNS uniqueidentifier
    AS
    BEGIN
    RETURN (SELECT ID FROM RandomView)
    END

    The view is required because it's not possible to directly use NEWID in a scalar function.

    You can then map the GetNewId user-defined function using LINQ to SQL's Function attribute. Again, see chapter 8 for the details.

    That's it! You can now write LINQ queries as usual. Here is an example to pick a random object:

    var tool = db.Tools.OrderBy(t => db.GetNewId()).First()

    Here is another example that uses GetNewId to sort results randomly: 

    var tools =
      from tool in db.Tools
      orderby db.GetNewId()
      select tool.Name;

  • LINQ in Action samples source code

    LINQ in Action won't be available as a paper book before January, but the e-book is already available in preview, and of course .NET 3.5 and Visual Studio 2008 are there. This is why we are now able to publish the complete source code for all the samples included in the book (this includes updated source code for LINQ to Amazon). This download is available for free. All the examples contained in the book and sample projects are included in both C# and VB.NET.

    Feel free to download the source code even if you don't own the book (yet) and provide feedback in the book's forum.

    Enjoy LINQ!

More Posts Next page »

Featured Item

This Blog

Sponsoring

Syndication

Tags

No tags have been created or used yet.