EF Core 3.1 breaks left join with no navigation property
Just recently my team took on the challenge of upgrading our codebase from .NET Core 2.2 to .NET Core 3.1. Along the way we encountered a quirky issue which caused us much befuddlement. Should you be befuddled too, then maybe this can help you.
Whilst running our app, we started encountering an error with an Entity Framework Query that looked like this:
Join me!
As EF Core tried to join from the Things table to the Problematic table (some obfuscation in table names here), that which worked in .NET Core 2.2 was not working in .NET Core 3.1. Digging into the issue, we discovered EF Core was generating an invalid LEFT JOIN:
Do you see it? Probably not; it took us a while too... The issue lay here:
This should actually have been:
For some reason EF Core was looking for ThingThingId where it should have looked for ThingId. But why?
Navigation properties to the rescue!
This was the Problematic class:
If you look closely you'll see it has a ForeignKey but no accompanying Navigation property. So let's add one:
With this in place our app starts generating the SQL we need.
Discussion in the ATmosphere