🇷🇺 За пол года работы с Entity Framework Core я понял, что AutoInclude - это зло.
AutoInclude - это метод, конфигурирующий автоматическую загрузку связанных сущностей из базы данных. По-умолчанию, такие сущности не загружаются, т.к., очевидно, что это негативно сказывается на произвольности.
Да, у любого функционала есть своё назначение и при грамотном использовании он будет работать так, как надо, но именно только при грамотном использовании.
С большой долей вероятности, вы забудете, что в DbContext сконфигурирован AutoInclude для какой-то сущности и в какой-то момент производительность запросов начнёт стремительно падать. А когда решите отключить AutoInclude, то заметите, что существующий функционал выбрасывает ошибки, т.к. в нём ожидаются какие-то связанные данные.
Решение всех этих проблем: не ленится писать Include для каждого конкретного запроса, включая только те связанные сущности, которые нужны для этого запроса.
🇬🇧 After half a year I realized that AutoInclude is evil.
AutoInclude is a method that configures an automatic loading of related entities from the database. It's obvious, that these entities are not downloaded by default, because it affects on querying performance.
Yes, any functionality has its own purpose and with properly using, it will serve as designed, but only if using is proper.
I'm pretty sure, that you will forget, that AutoInclude was configured for some entity in DbContext and in some day the performance of the requests will slow down rapidly. And when you decide to remove AutoInclude, you'll face a bunch of errors, that were thrown by some functions, because they expect related data.
The solution for all these problems is to use Include for each query and include only those entities that are necessary for the specific request.
Post #10
306
- ✍ 3