# System.InvalidOperationException: A navigation property 'NavigationName' is null. Related data must be loaded using Include or other eager loading methods.

- **ID:** `dotnet/ef-core-navigation-property-null-after-include`
- **Domain:** dotnet
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Entity Framework Core navigation property is null because related data was not eagerly loaded with .Include() or .ThenInclude() before accessing it after a query.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 6.0 | active | — | — |
| 7.0 | active | — | — |
| 8.0 | active | — | — |
| 9.0 | active | — | — |

## Workarounds

1. **Add .Include() with .ThenInclude() for nested navigation properties. Example: var orders = context.Orders.Include(o => o.Customer).ThenInclude(c => c.Address).ToList();** (95% success)
   ```
   Add .Include() with .ThenInclude() for nested navigation properties. Example: var orders = context.Orders.Include(o => o.Customer).ThenInclude(c => c.Address).ToList();
   ```
2. **Use explicit loading with .Collection().Load() or .Reference().Load() after the query. Example: var order = context.Orders.First(); context.Entry(order).Collection(o => o.OrderItems).Load();** (85% success)
   ```
   Use explicit loading with .Collection().Load() or .Reference().Load() after the query. Example: var order = context.Orders.First(); context.Entry(order).Collection(o => o.OrderItems).Load();
   ```
3. **Enable lazy loading by installing Microsoft.EntityFrameworkCore.Proxies and configuring: optionsBuilder.UseLazyLoadingProxies(); then ensure navigation properties are virtual.** (90% success)
   ```
   Enable lazy loading by installing Microsoft.EntityFrameworkCore.Proxies and configuring: optionsBuilder.UseLazyLoadingProxies(); then ensure navigation properties are virtual.
   ```

## Dead Ends

- **Adding .Include() to the query but missing .ThenInclude() for nested navigation properties** — EF Core requires explicit .ThenInclude() for second-level navigation properties; only Include() loads the immediate property but not its children. (75% fail)
- **Using .Load() after the query without calling .Collection() or .Reference() correctly** — Explicit loading with .Load() requires specifying the navigation property via .Collection() or .Reference() first; incorrect syntax leads to same null error. (60% fail)
- **Setting LazyLoadingEnabled = true in DbContext but not installing the Microsoft.EntityFrameworkCore.Proxies package** — Lazy loading requires both configuration and the Proxies NuGet package; missing the package causes no automatic loading and null navigation properties. (80% fail)
