ExpressionObserver and Where

Sep 27, 2010 at 10:59 AM


I use Obtics with Silverlight 4. I wonder about my experience.

In the following example _versionableObjectsViewModels is observable, and I would like to filtered collection with this predicate: item.LastVersion! = null.

My first try was:

var xx = _versionableObjectsViewModels.Where(vovm => vovm.LastVersion != null);

I realized that if an item changes LastVersion value with null, xx does not changed... I therefore looked for a long time to find:

var xx = ExpressionObserver.Execute(() => _versionableObjectsViewModels.Where(vovm => ExpressionObserver.Execute(() => vovm.LastVersion != null))).Cascade();

Is this the right way? If so why don't have not do simpler?

Best regards,


Sep 28, 2010 at 10:33 AM

Hi Vincent,

I think something like:

var xx = ExpressionObserver.Execute(() => _versionableObjectsViewModels.Where(vovm => vovm.LastVersion != null)).Cascade();

should work better.





Sep 28, 2010 at 1:00 PM


I already tried that, but it does not work: (


Sep 28, 2010 at 5:24 PM

Hi Vincent,

The reason your code works, I guess, is because you included the Obtics.Collections namespace in the using directives. The 'Where' method that is being used in that case is the Obtics.Collections.ObservableEnumerable.Where method instead of the System.Linq.Enumerable.Where method.

When working with the ExpressionObserver you should make sure that the System.Linq.Enumerable methods are used. That means including System.Linq instead of Obtics.Collections in your using directives.

ExpressionObserver will translate the call to the System.Linq.Enumberable.Where method to a call to the Obtics.Collections.ObservableEnumerable.Where method and translate your lambda expression as well. It actually can't do anything with the Obtics.Collections.ObservableEnumerable.Where method itself.



Sep 29, 2010 at 12:40 PM

Okay, thanks you, it works, but then in which case the use of Where Obtics.Collections is required ?


Sep 30, 2010 at 7:57 AM

In simple cases I don't think the using of Obtics.Collections would ever be required. You could use it if you would want to construct observable expressions manually. (Not using ExpressionObserver)

ExpressionObserver translates ordinary expressions to observable ones and maps object LINQ methods to observable equivalents in Obtics.Collections.ObservableEnumberable.



Sep 30, 2010 at 8:53 AM

ok, thanks you :)