Support filtered Include
See original GitHub issueWe keep this issue to track specifying filters inline when you specify eager loading in a query. However there are many scenarios that can be satisfied with global query filters:
Please learn about global query filters
We are seeing that a large portion of the scenarios customers want this feature for can already be better addressed using global query filters. Please try to understand that feature before you add your vote to this issue.
We are keeping this issue open only to represent the ability to specify filters on Include on a per-query basis, which we understand can be convenient on some cases.
Original issue:
Doing a .Where()
inside a .Include()
is allowed (by the syntax, it fails in execution). However, if you then follow that up with a .ThenInclude()
, like so:
.Include(t => t.Ratings.Where(r => !r.IsDeleted))
.ThenInclude(r => r.User)
You get the following error:
‘IEnumerable<Rating>’ does not contain a definition for ‘User’ and no extension method ‘User’ accepting a first argument of type ‘IEnumerable<Rating>’ could be found (are you missing a using directive or an assembly reference?)
Is this something you’re aware of and going to allow in a future version, or am I just doing something wrong and It’s already supported?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:519
- Comments:199 (42 by maintainers)
Top GitHub Comments
Fixed in 21b9a35db594f7a383e855f922babbe54b3d38c5
Example:
Supported operations: Where, OrderBy/ThenBy, Skip, Take.
Only one filter allowed per navigation, so for cases where the same navigation needs to be included multiple times (e.g. multiple ThenInclude on the same navigation) apply the filter only once, or apply exactly the same filter for that navigation.
Example:
or
Feature will ship in the next preview, but should be available in our daily builds shortly for anyone interested in taking an early look. If you find some problems please file new issue as this thread is already very long.
Don’t underestimate the value of filtered include. It was a top request in ef 6. I came across this requirement on my first ef 7 project. I’d take that over lazy loading any day.