dotnet / dotnet/fsharp

leftOuterJoin is different from C# version, workaround doesn't work for double left join

Open
#6,552 10 comments 11 reactions 0 assignees View on GitHub
Area-Queries Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

I'm creating this issue as a discussion about **leftOuterJoin** operator. Current implementation is inconsistent with C# version and libraries are reluctant to support F# version as well which leads to lack of very useful tools.
For example let's take [Linq2Db issue ](https://github.com/linq2db/linq2db/issues/417) that is not fixed for years or [SQLProvider workaround](https://github.com/fsprojects/SQLProvider/pull/590/files) which introduced another operator.
The key issue can be visible here

**C#**
```
.GroupJoin(
name,
c => c.ParentId,
p => p.ParentId,
(o, gr) => new { o = o; gr = gr })
.SelectMany(
t => t.gr.DefaultIfEmpty(),
(o, i) => new { o = o; gr = gr; i = i}
)
```

**F# equivalent when applying leftOuterJoin**
```
.GroupJoin(
name,
c => c.ParentId,
p => p.ParentId,
(o, gr) => new { o = o; gr = gr.DefaultIfEmpty() })
.SelectMany(
t => t.gr,
(o, i) => new { o = o; gr = gr; i = i}
)
```

Microsoft [documented C# behaviour](https://docs.microsoft.com/en-us/dotnet/csharp/linq/perform-left-outer-joins) of `DefaultIfEmpty()` insertion which is different [from F# behaviour](https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/FSharp.Core/Query.fs#L249-L250), which leads to the issues.
So my question is shouldn't a breaking change be made to equalize left joins and let F# developers use C# tools?

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.