Entity Framework: a proxy collection for displaying a subset of data
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?
Ended up on CollectionView
/CollectionViewSource
stuff.
精彩评论