Good day, dear! I want to ask probably a stupid question - why do I need the Include method in the Entity Framework? I tried to write code with it and without it, checked the generated SQL code using LINQ Pad, but found no difference. Where is this method necessary or useful? What can be done with it, which is impossible or inconvenient without it? Thank you in advance!

1 answer 1

The code probably uses Lazy Loading. To disable it, you need to mark all DbSet<> properties of the DbSet<> class as virtual . In this case, when executing .ToList() in the data of the related objects will be null . To fill them, you need to force .Include() .

  • when lazy loading is disabled, the virtual modifier is missing from the navigation property. without ef indicating that it is necessary to load the related entities ( Include(), Load() ), the navigation properties will be null - Bald