Apress Access

Programming Reactive Extensions and LINQ

By Jesse Liberty , Paul Betts

  • eBook Price: $31.99
Buy eBook Buy Print Book
A deep dive into the next important .NET technology: Reactive Extensions, also known as LINQ for Events.

Full Description

  • Add to Wishlist
  • ISBN13: 978-1-4302-3747-1
  • 184 Pages
  • User Level: Beginner to Advanced
  • Publication Date: October 25, 2011
  • Available eBook Formats: EPUB, MOBI, PDF

Related Titles

  • Windows 10 for the Internet of Things
  • DevOps on the Microsoft Stack
  • Practical Microsoft Visual Studio 2015
  • Develop Microsoft HoloLens Apps Now
Full Description

Pro Reactive Extensions and LINQ is a deep dive into the next important technology for .NET developers: Reactive Extensions. This in-depth tutorial goes beyond what is available anywhere else to teach how to write WPF, Silverlight, and Windows Phone applications using the Reactive Extensions (Rx) to handle events and asynchronous method calls.

Reactive programming allows you to turn those aspects of your code that are currently imperative into something much more event-driven and flexible. For this reason, it’s sometimes referred to as LINQ for Events.

Reactive programming hinges on the concept of the observable collection, as opposed to the simple enumerable collection with which we’re all familiar. For example, to extract data from a collection and add it to a list box, you would traditionally iterate through the list box, extracting each object in turn. This approach works fine, but it requires significant knowledge about the data you’re working with, which can be limiting. In Rx programming, you're instead informed about each object in turn and then free to react to each notification however you like, which affords much greater flexibility.

This book shows you how reactive programming can be applied to a range of situations—from WPF applications to Windows Phone apps—to improve coding efficiency and boost performance.

What you’ll learn

  • How to create, debug and manage reactive extensions in many situations
  • The observer pattern and how it can be applied to your projects
  • How to avoid spaghetti code by using Rx to manage your asynchronous methods
  • How to use SelectMany to explore the heart of the Reactive Extensions
  • How to come to grips with the reactive user interface framework for building both small and large applications

Who this book is for

This book will be most beneficial to existing .NET developers with a grounding in WPF, Silverlight and C#, who want to take their skills further using the powerful reactive programming approach.

Table of Contents

Table of Contents

  1. Welcome to LINQ and RX
  2. Core LINQ
  3. Core Rx
  4. Practical Rx
  5. Inside Rx and LINQ
  6. LINQ to SQL
  7. Rx and Javascript
  8. Reactive UI: Rx and MVVM
  9. Testing Rx
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.


If you think that you've found an error in this book, please let us know by emailing to editorial@apress.com . You will find any confirmed erratum below, so you can check if your concern has already been addressed.

On page 1:

source code download zip file corrupted. Can't open it.
Author Comment:

We think this issue should be overcome without much trouble.

We tested the file by downloading/extracting it ourselves using Firefox + WinZip, and the process worked flawlessly. Chrome and IE 9 seem to work, as well.

Can we trouble you to try again, this time with a different browser/utility combination?

On page 7:

Add the try/finally and Dispose call in this first exploded example of IEnumeraot<T> use, or better yet explain in a sidebar that you are intentionally going to omit for clarity the real cleanup code generated (different for generic and non-generic IEnumerator of course, with the non-generic only sometimes generating a Dispose call).

People new enough to need this sort of IEnumerable explosion to begin with, are also new enough to see the disposing portion once as well. Then omit it from then on.

On page 7:

The first line of the LINQ query is a from statement, in this case creating the temporary variable
number ....

replace with

The first line of the LINQ query is a from statement, in this case creating the temporary variable
num ....

On page 13:

In the text:

"Rx works with collections that implement an extension to IEnumerable, IQueryable, which will refer to as observable collections."

should be:

"Rx works with collections that implement the push-oriented dual of IEnumerable, called IObservable, which we will refer to as observable collections."

and perhaps expand with a sidebar:

"NOTE: The related IQueryable which is used to provide whole query sequence translation and execution (such as LINQ to SQL's translation of a entire LINQ query sequence into T-SQL) has a dual, called IQbservable, which is out-of-scope for this book."

[ed: There is currently no IQbservable dual to the in-depth IQueryable and LINQ provider creation in Programming Microsoft LINQ in Microsoft .NET Framework 4, and MSDN's IQbservable coverage is very weak. Maybe this book will evolve into including that detail, but for now it would be good to call out the intentional out-of-scope omission early here.]

On page 14:
The suggested rewrite of Listing 1-1 returns .GetEnumerator() on the list of ints, it should return the query's enumerator to properly reproduce 1-1.

IEnumerator<int> e = ints.GetEnumerator();

should be:

IEnumerator<int> e = query.GetEnumerator();

On page 20:

In the Note at the top of the page:

"...that does not necessarily start with the from clause."

should be:

"...that omits the from clause whose purpose as syntactic sugar to introduce an enumerable data source to the query is not needed."

[ed: obviously there is no From extension method, and a new person might go looking for one without this info since you say "not necessarily start with". Sure, you can mix the query syntax form of 'from' with method syntax of other ops, but that would just confuse a new person at the intended level of this Note which is what a 100% method syntax equivalent entails.]

On page 30:

Bottom paragraph on page says:

"...it contains a collection of books, each of which contains a collection of authors."

it should say:

"...it contains a collection of a list of authors (IEnumerable<List<Author>>) since each element b.Authors is itself a collection."

The related example at the top of the next page (31) happens to work but should say:

foreach (var bookAuthors in q)
foreach (var auth in bookAuthors)


    1. Pro C# 5.0 and the .NET 4.5 Framework


      View Book

    2. Expert ASP.NET Web API 2 for MVC Developers


      View Book

    3. Machine Learning Projects for .NET Developers


      View Book

    4. Pro ASP.NET MVC 5 Platform


      View Book