dotnet / dotnet/efcore

Handle exact filtered includes without giving an error

Open
#33,352 0 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

****
I have 2 functions like below:

```
public static IQueryable GetAcessibleContactsQueryable(this IQueryable queryable, long for_user_id)
{
queryable = queryable
.Include(x => x.Groups).ThenInclude(x => x.Group).ThenInclude(x => x.GroupUsers.Where(x => x.user_id == for_user_id))

//....
//Some other filters
//....
return queryable;
}

public static IQueryable GetIncludeQueryableForContactBase(this IQueryable queryable, long? for_user_id = null)
{
//We are including GroupUsers to fetch current user's permission with respect to this contact
queryable = queryable
.Include(x => x.Groups).ThenInclude(x => x.Group).ThenInclude(x => x.GroupUsers.Where(x => x.user_id == for_user_id))
.Include(x => x.Emails)
.Include(x => x.Phones);

return queryable;
}
```
When we execute `GetAcessibleContactsQueryable` and `GetIncludeQueryableForContactBase` we get an error saying we can't apply `.Where(x=> x.user_id == for_user_id)` more than once within a filtered include.

**Ideally**
EF Core should not give out an error if `for_user_id` is same for both the filtered includes. As the end result is a single filtered .Includes

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.