Click here to Skip to main content
Click here to Skip to main content

ObservableLinq

, 30 Apr 2014
Rate this:
Please Sign up or sign in to vote.
An open source library of Linq operators on ObservableCollection

Introduction

ObservableLinq is an open source, portable class library that can be easily deployed from nuget and used in .NET 4.5, Windows Phone 8 and Windows Store applications. ObservableLinq proposes to implement a subset of the LINQ operators on ObservableCollection, where source collection changes are automatically reflected in the result collection.

Using the Code

Project Data between Different Domains

Larger applications are often architectured in multiple layers, across multiple tiers. The different layers can enrich data coming from another layer with new attributes, filters and sort criteria.

Consider an editable data grid that contains personal data in an MVVM application. The model class will contain records with first name, last name, etc. Your view model might wrap the model object and have additional attributes, like 'IsEditing' and 'IsChanged'. Your UI layer will transform the view model into rows in the datagrid.

Using ObservableLinq not only allows you to project your model into view models, but when your original collection changes, it will keep the view model collection up to date, without losing the added data on the view model level.

Change between Different Views of the Same Collection

ObservableLinq provides a special collection class, called ObserverCollection. This collection can be instructed to follow a different observable collection. However, ObserverCollection can change from one observed collection to another at any time. Items present in both will be retained and moved to their new position.

Let's consider our personal data view models from before. We can project that collection into one where we sort by first name and another one where we sort by last name. Maybe another one, where we filter out unchanged items. Then, we bind our datagrid to an observer collection that switches between these collections according to user input...

Display Changes Visually to the User

The basic modification events on the ICollectionChanged interface can be translated into animations like in the figure above, which results in a user interface that is both appealing and gives plenty of visual clues to the user in order to correctly understand the underlying data manipulation.

Points of Interest

The project is currently in an "alpha" state. The currently supported set of operators is the following:

  • Select
  • Distinct
  • Where
  • OrderBy
The goal for version 1.0 is to have functional parity with Linq on these operators and ThenBy.

Install the library from the nuget command prompt using the following command:

Install-Package ObservableLinq -Pre 

ObservableLinq is hosted on GitHub, contributions are welcome. Please read the guidelines in the project "readme" file.

History

  • April 30, 2014 - Initial article submission

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

About the Author

Csaba Fábián
Software Developer (Senior) Milestone Systems
Denmark Denmark
No Biography provided
Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 30 Apr 2014
Article Copyright 2014 by Csaba Fábián
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid