-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Comments
This would be extremely helpful! |
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 */); |
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. |
Related items: |
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: 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 ;) |
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:
By adding leftjoin we'd get this:
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)
The text was updated successfully, but these errors were encountered: