Entifyframework core 2.0 filter in ThenInclude

entity-framework-core linq-to-entities

Question

I am using EF core 2.0 and would like to filter the child collection. Can anyone help me how to do this in EF core 2.0?

    var items = await _context.RiskType
                              .Include(r => r.Categories)
                              .ThenInclude(category => category.Alerts)
                              .ToListAsync();

In the above code i want to filter category.Alerts.where(alert=>alert.caseId==1)

Thanks

1
2
11/8/2017 10:56:22 AM

Popular Answer

Use EF plus and this works. You may filter on either level. https://entityframework-plus.net/query-include-filter

var items = ctx.RiskType.IncludeFilter(r=>r.Categories).IncludeFilter(x => x.Categories.Select(p=>p.Alerts.Where(alert=>alert.caseId==1)))
                     .ToList();

This works like Include with filter which applies on database level (you see it in db profiler).

1
7/26/2019 1:22:11 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow