刷新映射中过滤的集合
我有一个在映射级别进行过滤的集合,以使用数据库中的“isDeleted”列启用软删除。
映射如下所示:
HasMany(x => x.UploadedFiles).Where("IsDeleted = 0")
当我为某些项目设置 isDeleted 属性时,集合不会自动刷新以反映删除,直到我重新加载实体。
有没有办法在不重新加载实体的情况下强制“重新过滤”?
I have a collection which is filtered at the mapping level to enable soft deletion using an "isDeleted" column in the database.
The mapping looks like this:
HasMany(x => x.UploadedFiles).Where("IsDeleted = 0")
When I set the isDeleted property for some items the collection does not automatically refresh to reflect the deletion until I reload the entity.
Is there any way to force a "refiltering" without reloading the entity ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
映射中的Where子句用于在获取期间进行过滤。它不在运行时使用,这就是为什么当您设置 IsDeleted = true 时,您没有看到 UploadedFiles 从集合中删除的原因。我不认为在不重新加载拥有它的实体的情况下刷新集合是可能的。
我建议在对象模型中表达您的意图。
然后修改您的映射以访问您的支持字段......
The Where clause in the mapping is to filter during fetching. It is not used at run-time, which is why you're not seeing UploadedFiles drop out of your collection when you set IsDeleted = true. I don't believe it is possible to refresh the collection without reloading the entity that owns it.
I would recommend expressing your intent in your object model.
And then modifying your mapping to access your backing field...