Entity Framework: a proxy collection for displaying a subset of data

Posted by Jefim on Stack Overflow See other posts from Stack Overflow or by Jefim
Published on 2010-06-10T05:36:58Z Indexed on 2010/06/10 5:42 UTC
Read the original article Hit count: 175

Imagine I have an entity called Product and a repository for it:

public class Product
{
    public int Id { get; set; }
    public bool IsHidden { get; set; }
}

public class ProductRepository
{
    public ObservableCollection<Product> AllProducts { get; set; }
    public ObservableCollection<Product> HiddenProducts { get; set; }
}

All products contains every single Product in the database, while HiddenProducts must only contain those, whose IsHidden == true. I wrote the type as ObservableCollection<Product>, but it does not have to be that.

The goal is to have HiddenProducts collection be like a proxy to AllProducts with filtering capabilities and for it to refresh every time when IsHidden attribute of a Product is changed.

Is there a normal way to do this? Or maybe my logic is wrong and this could be done is a better way?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about collections