Can’t make GroupJoin work. NavigationExpandingExpressionVisitor exception

Glad you asked.

The problem is that EF Core team doesn’t (and does not want to) provide GroupJoin translation. See my comments on this EF Core GitHub thread Query: Support GroupJoin when it is final query operator #19930 and linked discussions where I was trying to convince them to include such support (which should have been extremely easy for what they do to support LINQ left outer join pattern for instance). So please go there and vote, otherwise the argument is that it “has no value”.

With that being said, with current EF Core either add and use collection navigation property (preferable), or use correlated subquery instead of GroupJoin, e.g. replace

.GroupJoin(dbContext.Subscriptions,
    u => u.Id,
    s => s.UserId,
    (u, subscriptions) => new
    {
        User = u,
        Subscriptions = subscriptions
    })

with

.Select(u => new
{
    User = u,
    Subscriptions = dbContext.Subscriptions.Where(s => u.Id == s.UserId) // <--
})

Leave a Comment