有没有办法在Linq中过滤LoadWith
我目前有ReportCategory和Reports表。我想检索所有类别,然后只想加载活动报告。
这是我到目前为止所做的。
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<ReportCategory>(report => report.Reports);
db.LoadOptions = dlo;
var categories = from c in db.ReportCategory
where c.InUse == true
select c;
它按预期返回每个类别的所有活动类别和所有报告,但我不需要所有报告,我只需要标记为InUse的那些。
所以我试过这个......
dlo.LoadWith<ReportCategory>(report => report.Reports.Where(r => r.InUse == true));
但是我收到了以下错误。
InvalidOperationException:指定的表达式必须是p.A形式,其中p是参数,A是属性或字段成员。
有没有办法用LoadWith做到这一点,还是我应该转向使用连接?
答案 0 :(得分:8)
发现它......
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<ReportCategory>(report => report.Reports);
dlo.AssociateWith<ReportCategory>(r => r.Reports.Where(i => i.InUse == true));
db.LoadOptions = dlo;
这将带回所有类别和活动报告