开发者

Refreshing collections filtered in the mapping

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 t开发者_运维问答o reflect the deletion until I reload the entity.

Is there any way to force a "refiltering" without reloading the entity ?


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")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜