Replies: 5 comments 13 replies
-
Anyone willing to hammer out the precise translation rules? |
Beta Was this translation helpful? Give feedback.
-
I think it would be a very useful feature. How do we go about promoting this to a proposal?
Unless I'm missing something, the translation would be pretty simple. This: from person in people
leftjoin pet in pets on person.Id equals pet.Id would become: from person in people
join pet in pets on person.Id equals pet.Id into tmp
from pet in tmp.DefaultIfEmpty() |
Beta Was this translation helpful? Give feedback.
-
The current syntax is ugly and unnecessarily verbose adding additional parameters to the query for little reason. Please consider adding left/right join ASAP that just wraps this into one and makes it work effectively so that we can save our sanity. |
Beta Was this translation helpful? Give feedback.
-
I really feel that this is in the wrong location, ie "Discussions". Discussions are far less discoverable since I believe most users go to "Issues" when searching for things. I also can't really find a good way to vote for this item here. I feel this has low visibility because of this. Anyone that works with LINQ on a day-to-day basis (which I would guess to be a large portion of C#/VB devs) would enthusiastically advocate for these enhancements! Please reconsider opening up #508. Related items: |
Beta Was this translation helpful? Give feedback.
-
This would be incredibly useful - my understanding is that this is the blocker for dotnet/efcore#12793 which is an ongoing source of frustration. The main SO topic for workarounds has passed the 250k view mark, and still can only return an |
Beta Was this translation helpful? Give feedback.
-
@uyhung commented on Sun Feb 14 2016
Please consider to extend Linq to add a new keyword leftjoin or rightjoin. I'm sure a lot of .NET developers dream about this keyword when doing LEFT JOIN using SingleOrDefault() in conjunction with "into". Mimic left join using SingleOrDefault + "into" is very unclear. The same issue with how we do with Group By.
By supporting this keyword you really bring Linq to a higher level.
@DavidArno commented on Mon Feb 15 2016
Could you please expand this request with some details of how left and right joins are currently achieved with linq, how they might be achieved with method chaining and how the proposed query syntax might translate into a method chain?
@HaloFour commented on Mon Feb 15 2016
For reference:
How to: Perform Left Outer Joins (C# Programming Guide)
@svick commented on Mon Feb 15 2016
I don't think outer joins are actually a common operation in LINQ. In SQL, everything has to be returned in a single flat table, so outer join makes perfect sense. But in LINQ, you have group joins, which I believe are much more natural and easier to work with.
@HaloFour commented on Mon Feb 15 2016
@svick
If you're dealing with a 1:0..1 relationship and you want to flatten that result into an anonymous type you are still required to jump through these hoops. It's not pleasant and often trips up junior devs.
@svick commented on Mon Feb 15 2016
@HaloFour Yes, but what I'm trying to say is that you shouldn't need to flatten results in common cases. If you do, you're writing a more complicated query and in return you get something that's harder to work with. Just return the group directly (i.e. something like
select new { person, pets = gj }
).@HaloFour commented on Mon Feb 15 2016
@svick
If you were flattening the results in the query it's likely that you need to get the final results in a flattened shape anyway, so using group join doesn't fix anything it just moves the problem downstream. Not to mention since queryable providers recognize the outer join pattern and understand the relationships that it entails they will create much more optimized SQL for it.
@uyhung commented on Fri Feb 19 2016
Guys I'm not talking about whether it's possible or there's a better way to do outer join in Linq, I just wanna suggest extending the LINQ to bring it up to a higher level of readability, stylish, more SQL-like. When I'm showing some examples of Linq to my friends who are working on other technology stacks such as PHP, Java etc. at the first glance looking at simple code samples they all say "wow it's great!", but when it comes to show demo about how to do Linq with outer join, group by, having etc... their face looks a little silly :)
@Unknown6656 commented on Tue Feb 16 2016
I know that this comment is slightly out of place, but I would rather like to see 'small' functions like
Count
,Sum
,FirstOrDefault
,LastOrDefault
,Reverse
etc. implemented in LINQ thanLeftJoin
orRightJoin
-- but maybe this is my personal opinion :)Beta Was this translation helpful? Give feedback.
All reactions