Linq: Query Nested Collections

11 July 2009

Just a quicknote – if you have a collection of objects (of a given type) where each object of that type contains its own collection, you can select all items across the nested collections by using multiple from statements.

As an example, imagine a case where you have a collection of objects that each has a collection of KeyValues pairs. The code below allows you to select all distinct keys from those key values pairs.

var distinctKeys = (from i in Items
                    from nested in i.SecondLevelCollection
                    orderby nested.SomeProperty ascending
                    select nested.SomeProperty).Distinct();

Unrelated quicknote: Use the Intersect extension method to find object common to two collections (obvious really!)  e.g.

var common = ColectionA.Intersect(CollectionB);



post a comment / view comments   (currently 0 comments)

WPF: Deepzoom Workaround

08 July 2009

Here is a nice way to create a “deep zoom” style effect in WPF: http://blogs.windowsclient.net/joeyw/archive/2008/08/05/pan-and-zoom-deepzoom-style-in-wpf.aspx



post a comment / view comments   (currently 0 comments)