dotnet / dotnet/efcore

[Feature Request] Same filter Includes should result in union include instead of error

Open
#34,220 6 comments 0 reactions 0 assignees View on GitHub
area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Currently, if you have a complex query which dynamically applies .Includes to a query. Sometimes the query may result in having 2 similar .Includes with filter, like:

```
.Include(x => x.Users.Where(y => y.user_id == user_id))
.Include(x=> x.Users.Where(y=> y.user_id == user_id2))
```

In such cases, we current get an error:
```
.Where(x => x.user_id == user_id_2)' and 'navigation
.Where(y => y.user_id == user_id_0)' have both been configured on the same included navigation. Only one unique filter per navigation is allowed.
```

Instead, EF should construct a union of .Includes like:
`.Include(x=> x.Users.Where(y=> y.user_id == user_id || y.user_id == user_id2))`

If this is not possible, then the last include should win:
`.Include(x=> x.Users.Where(y=> y.user_id == user_id2))`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.