开发者

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

开发者 https://www.devze.com 2023-01-03 10:53 出处:网络
Imagine I have an entity called Product and a repository for it: public class Product { public int Id { get; set; }

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消