我在我的数据库(IsDeleted
字段)中使用软删除。我正在积极使用LoadWith
和AssociateWith
方法来检索和过滤嵌套记录。
这件事AssociateWith
只适用于代表一对多关系的属性。
DataLoadOptions loadOptions = new DataLoadOptions();
loadOption.LoadWith<User>(u = > u.Roles);
loadOption.AssociateWith<User>(u = > u.Roles.Where(r = > !r.IsDeleted));
在上面的示例中,我只是说:我想检索具有相关(未删除)角色的用户。
但是当我有一对一的关系时,例如Document
-> File
(唯一一个文件与文档相关)我无法过滤软删除对象:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOption.LoadWith<Document>(d = > d.File);
// the next certainly won't work
loadOption.AssociateWith<File>(f = > !f.IsDeleted);
那么,是否有任何想法如何过滤一对一关系中的记录?
谢谢!