刷新映射中过滤的集合

发布于 2024-10-04 07:59:03 字数 240 浏览 1 评论 0原文

我有一个在映射级别进行过滤的集合,以使用数据库中的“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-10-11 07:59:03

映射中的Where子句用于在获取期间进行过滤。它不在运行时使用,这就是为什么当您设置 IsDeleted = true 时,您没有看到 UploadedFiles 从集合中删除的原因。我不认为在不重新加载拥有它的实体的情况下刷新集合是可能的。

我建议在对象模型中表达您的意图。

private IList<File> uploadedFiles = new List<File();
public virtual IEnumerable<File> UploadedFiles {
    get {
        return uploadedFiles.Where(x => x.IsDeleted == false);
    }
}

然后修改您的映射以访问您的支持字段......

HasMany(x => x.UploadedFiles)
    .Access.CamelCaseField()
    .Where("IsDeleted = 0")

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.

private IList<File> uploadedFiles = new List<File();
public virtual IEnumerable<File> UploadedFiles {
    get {
        return uploadedFiles.Where(x => x.IsDeleted == false);
    }
}

And then modifying your mapping to access your backing field...

HasMany(x => x.UploadedFiles)
    .Access.CamelCaseField()
    .Where("IsDeleted = 0")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文