我在我的數據庫中使用軟刪除(IsDeleted
字段)。我正在積極使用LoadWith
和AssociateWith
方法來檢索和過濾嵌套的記錄。LINQ to SQL:過濾軟刪除嵌套對象
事情是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);
那麼,有沒有任何想法如何將一個一對一關係中篩選記錄?
謝謝!
不幸的是,這是行不通的。給出與'loadOption.AssociateWith(f =>!f.IsDeleted)'相同的錯誤:'子查詢不支持類型爲'Core.Entities.File'的'IsDeleted'。 –
Alex
2010-05-21 15:25:39