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!
- stackoverflow.com/questions/5159621/… here is a good example - Mikhail Tatarintsev
- Include allows you to load related entities not when accessed, but immediately. - beliy26rus
|
1 answer
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
virtualmodifier is missing from the navigation property. without ef indicating that it is necessary to load the related entities (Include(), Load()), the navigation properties will benull- Bald
|