Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding first-class left-join LINQ operator #12793

Open
JohnGalt1717 opened this issue Jul 25, 2018 · 5 comments
Open

Consider adding first-class left-join LINQ operator #12793

JohnGalt1717 opened this issue Jul 25, 2018 · 5 comments

Comments

@JohnGalt1717
Copy link

Describe what is not working as expected.

Doing outer joins is with linq are horrible and make for a mess of code that makes it difficult if not impossible to debug.

I.e:

from c in Context.Courses
join ci in Context.CourseItems on c.Id equals ci.CourseId

join tijoin in Context.TopicItems on ci.ItemId equals tijoin.TopicId into titrans
from ti in titrans.DefaultIfEmpty()

By adding leftjoin we'd get this:

from c in Context.Courses
join ci in Context.CourseItems on c.Id equals ci.CourseId
leftjoin ti in Context.TopicItems on ci.ItemId equals ti.TopicId

Yes it really is that ugly every single time simply because there isn't a leftjoin operator that does the same.

Would this break current providers? No, because it can be converted first to the ugly syntax they already support if they don't support the new stuff.

Would this slow anything down? Nope. Same stuff generated.

Would this introduce bugs in code? Nope, this is a new keyword that is highly likely to not be used in someone's code that would cause problems.

I'm very sure that this syntax is also causing developers to write bad code (because I've seen it) doing the following:

from c in Context.Courses
join ci in Context.CourseItems on c.Id equals ci.CourseId

let ti = (from i in Context.TopicItems where i.TopicId == ci.ItemId select I)

Which results in a sub select disaster which is INCREDIBLY SLOW.

Please save us from our insanity and work with the C# team to get this keyword added and make Entity Framework sane for left outer joins! (all right outer joins can be written as lefts so no need to confuse the matter)

@ajcvickers ajcvickers added this to the 3.0.0 milestone Jul 27, 2018
@divega divega changed the title Please stop the madness and add leftjoin Consider adding first-class left-join LINQ operator Aug 15, 2018
@StevenRasmussen
Copy link

This would be extremely helpful!

@jeffrey-igaw
Copy link

Yes! we every write left join query as below, this is not clear and not expectable what is mean.

_context.Users
    .GroupJoin(_context.Posts, u => u.Id,  p => p.UserId, posts => posts.DefaultIfEmpty())
    .SelectMany(g => new {User = g.Key, Posts = g.Value})
    .Something();

maybe we want to use as ..

_context.Users
    .LeftJoin(_context.Posts. u => u.Id, p => p.UserId, (user, post/* nullable? */) => new {user, post})
    .Where(/* something */); 

@OJacot-Descombes
Copy link

StackOverflow returns 1,337 results for "LEFT JOIN in LINQ". Yes, we need it, and not only in EF Core but also for LINQ-to-objects.

@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jan 23, 2019
@divega divega removed their assignment Sep 18, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 5.0.0 Nov 13, 2019
@ajcvickers ajcvickers modified the milestones: 5.0.0, Backlog Nov 15, 2019
@smitpatel smitpatel removed this from the Backlog milestone Mar 16, 2020
@ajcvickers ajcvickers added this to the Backlog milestone Mar 16, 2020
@StevenRasmussen
Copy link

@StevenRasmussen
Copy link

StevenRasmussen commented Oct 25, 2021

Anyone wanting this MUST also go to #361 and click both the up arrow and thumbs up just below the last item for your vote to be counted:
image

Yes... it looks like you're voting for the comment... which is against the idea... but you're actually voting for the idea. You can read the discussion around that in the comments.

The C# language must first implement this before EF could take advantage of it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants