Filtering LoadWith Results

Is there a way to filter LoadWith in Linq

I currently have ReportCategory and Reports tables. I want to get all categories, and then I only want to download active reports.

This is what I still have.

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; 

It returns all active categories and all reports for each category, as expected, but I do not need all reports, I only need those that are marked as InUse.

So I tried this ...

 dlo.LoadWith<ReportCategory>(report => report.Reports.Where(r => r.InUse == true)); 

but I get the following error.

InvalidOperationException: the specified expression must be of the form pA, where p is a parameter, and A is an element of a property or field.

Is there a way to do this with LoadWith, or just move on to using a connection?

+4
source share
1 answer

Found...

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

This returns all categories and active reports.

+8
source

Source: https://habr.com/ru/post/1340757/


All Articles