实体框架:用于显示数据子集的代理集合
想象一下,我有一个名为 Product 的实体及其存储库:
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; }
}
所有产品都包含数据库中的每个产品,而 HiddenProducts 必须仅包含 IsHidden == true
的产品。我将类型编写为 ObservableCollection
,但不一定是这样。
目标是让 HiddenProducts
集合像具有过滤功能的 AllProducts
的代理一样,并在每次产品的 IsHidden
属性出现时刷新它被改变了。
有正常的方法可以做到这一点吗?或者也许我的逻辑是错误的,这可能是更好的方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终得到了
CollectionView
/CollectionViewSource
的东西。Ended up on
CollectionView
/CollectionViewSource
stuff.