Bindable LINQ

Reactive Programming for the .NET Framework

Dependencies

Bindable LINQ enables propagation of change by monitoring various dependencies on the query. This page details the different kinds of dependencies that are available in Bindable LINQ.

Source Dependencies

All queries have either a source collection or item that may raise events indicating changes. For iterators and aggregators, if a source collection implements the INotifyCollectionChanged or IBindingList interfaces, Bindable LINQ will automatically monitor the source collection for changes. For operators, the INotifyPropertyChanged interface will be monitored.

In most cases, Bindable LINQ is smart enough to do the minimum amount of work possible per change notification. For instance, if an item is added to a source collection, a Bindable LINQ Where query will receive the Add event, and will filter only the changed item - not the entire result set. In some cases, such as Reset events, the entire collection will be re-evaluated.

Automatic Dependency Discovery

Many Bindable LINQ queries, such as Where, Select and OrderBy, take lambda expressions as parameters, which are usually quite important to the results of the query. In these cases, Bindable LINQ will automatically parse the expression tree and discover additional dependencies. For example, in the following query:

var query = contacts.Where(c => c.Name.Contains(textBox1.Text));

The Name property of each contact item, and the Text property of TextBox1, are important to this query. Bindable LINQ will detect this and set up dependencies on these two properties. If the Name of an item changes, the item will be re-filtered. If the Text of the TextBox changes, the entire result set will re-evaluate.

Dependencies discovered in the lamda expressions can be broken into two categories:

This expression tree analysis is usually quite fast, but it can cause unintended side effects, and it may be faster to skip. To this end, each query which conducts automatic dependency discovery provides an overload which enables you to disable automatic dependency discovery:

var query = contacts.Where(c => c.Name.Contains(textBox1.Text), DependencyDiscovery.Disabled);

Manual Dependencies

Some queries may not reference an external item, but may still have dependencies on external items. These dependencies can be added manually using the DependsOn extension methods. This can also be useful if automatic dependency discovery is disabled.

var query = contacts.Where(c => c.Name.Contains(textBox1.Text), DependencyDiscovery.Disabled)
                    .DependsOn("Name")
                    .DependsOn(textBox1, TextBox.TextProperty);