.net 使用结果筛选加载项

.net 使用结果筛选加载项,.net,linq,.net,Linq,有没有办法在Linq中过滤LoadWith 我目前有ReportCategory和Reports表。我想检索所有类别,然后只想加载活动报告 这就是我目前所拥有的 DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<ReportCategory>(report => report.Reports); db.LoadOptions = dlo; var categories = from c in db.Report

有没有办法在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;
DataLoadOptions dlo=newdataloadoptions();
LoadWith(report=>report.Reports);
db.LoadOptions=dlo;
var categories=来自db.reportcategority中的c
其中c.InUse==true
选择c;
它将按预期返回所有活动类别和每个类别的所有报告,但我不需要所有报告,我只需要标记为InUse的报告

所以我试过这个

dlo.LoadWith<ReportCategory>(report => report.Reports.Where(r => r.InUse == true));
dlo.LoadWith(report=>report.Reports.Where(r=>r.InUse==true));
但我得到了以下错误

InvalidOperationException:指定的表达式的形式必须为p.A,其中p是参数,A是属性或字段成员

有没有一种方法可以通过LoadWith实现这一点,或者我应该直接使用联接吗?

找到了

DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<ReportCategory>(report => report.Reports);
dlo.AssociateWith<ReportCategory>(r => r.Reports.Where(i => i.InUse == true));
db.LoadOptions = dlo;
DataLoadOptions dlo=newdataloadoptions();
LoadWith(report=>report.Reports);
dlo.AssociateWith(r=>r.Reports.Where(i=>i.InUse==true));
db.LoadOptions=dlo;

这将返回所有类别和活动报告,因为
InUse
是一个
bool
,说
==true
是多余的。您可能需要考虑重命名<代码>使用< <代码> > <代码> iSimue<代码>。