有没有办法在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;
Run Code Online (Sandbox Code Playgroud)
它按预期返回每个类别的所有活动类别和所有报告,但我不需要所有报告,我只需要标记为InUse的报告.
所以我试过这个......
dlo.LoadWith<ReportCategory>(report => report.Reports.Where(r => r.InUse == true));
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误.
InvalidOperationException:指定的表达式必须是pA形式,其中p是参数,A是属性或字段成员.
有没有办法用LoadWith做这个或者我应该转移到使用连接?
Org*_*ey 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;
Run Code Online (Sandbox Code Playgroud)
这将带回所有类别和活动报告