-
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
Left Join #19296
Comments
@GRS-Leedo - I am not sure what pattern you are exactly referring to which worked in 2.2. Without looking at the LINQ query, it is hard for me to say if that was supported pattern or if it just worked in 2.2 because it evaluated everything on client. For 3.1 here is detailed documentation on LINQ pattern which translates to Left Join in SQL https://docs.microsoft.com/en-us/ef/core/querying/complex-query-operators#left-join |
Could you give me a chance to respond before you immediately close this? As mentioned in my post and more specifically, from the link,
Does not work in 3.1. It throws errors. Beyond not working, the translated query is the convoluted combination of outter and inner joins when a simple translation to LEFT JOIN would be so much cleaner. To be VERY specific, this query ran perfectly in 2.2.6
In 3.1, the result is Again 2.2.6 worked. 3.1 doesn't work. Thoughts? |
The last paragraph in the documentation I linked specifically points out
In the complex query you have posted above, you are grouping into b & then into w and then another join before you use DefaultIfEmpty to flatten it out. it is not same as the first simple query you posted. The simple query you posted actually works correctly in EF Core 3.1 (It is same as the example shared in documentation.) If you rewrite your complex query so that after grouping into something next line is flattening it out using DefaultIfEmpty then it would at least work for left join. |
As suggested
Result Moving the lines of code made no difference. Changing the code to only have 1 Left Join
Resulted in No difference Again, this worked in 2.2.6, but does not work in 3.1. |
This is not writing DefaultIfEmpty in clause right after group join. You have a where clause in between. We do not support that pattern. No matter if it worked in 2.2.6. Write those lines like this as clearly showed in documentation. join bld in _context.tbl_Building1 on un.BldgID equals bld.Bldg_ID into b
from n in b.DefaultIfEmpty()//join wh in _context.Tbl_Warehouses on ord.Warehouse_ID equals wh.Warehouse_ID into w
//from m in w.DefaultIfEmpty()
where lab.scanID == ScanID |
Thank you very much for your help. It is truly appreciated. As a secondary question, why not simply have a left join rather than having to do pattern matching? It seems like it would be easier. |
@GRS-Leedo - Queryable operators are defined in BCL, we just merely use it. You can submit a feature request on https://github.com/dotnet/runtime |
The pattern described in https://docs.microsoft.com/en-us/ef/core/querying/complex-query-operators#left-join |
Anyone wanting this MUST go to #361 and click both the up arrow and thumbs up just below the last "comment" in the first post 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. |
I am not really sure if this is a LINQ or EF Core issue, but not having Left Joins is problematic.
In EF Core 2.2.6, there was a work around by by joining the table into name and then adding from another name in name.DefaultIfEmpty(). This worked.
In EF Core 3.1, this no longer works. If I understand correctly, EF Core tries to translate the LINQ syntax into a query that runs on the server. The query that it generates for the Left Join work around seems very convoluted and results in an error.
Are there plans to support a Left Join or to translate the work around into a left join?
Is there a functioning syntax to do a left join in EF Core 3.1?
Thanks.
Steps to reproduce
Further technical details
EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: