{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/ef-core-31-breaks-left-join-with-no-navigation-property",
  "description": "When upgrading from .NET Core 2.2 to 3.1, an invalid LEFT JOIN error was encountered. The issue was resolved by adding Navigation property.",
  "path": "/posts/ef-core-31-breaks-left-join-with-no-navigation-property",
  "publishedAt": "2020-01-02T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "sql server"
  ],
  "textContent": "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.\n\n\n\nWhilst running our app, we started encountering an error with an Entity Framework Query that looked like this:\n\nJoin me!\n\nAs 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:\n\nDo you see it? Probably not; it took us a while too... The issue lay here:\n\nThis should actually have been:\n\nFor some reason EF Core was looking for ThingThingId where it should have looked for ThingId. But why?\n\nNavigation properties to the rescue!\n\nThis was the Problematic class:\n\nIf you look closely you'll see it has a ForeignKey but _no_ accompanying Navigation property. So let's add one:\n\nWith this in place our app starts generating the SQL we need.",
  "title": "EF Core 3.1 breaks left join with no navigation property"
}