๐—•๐—ผ๐—ผ๐˜€๐˜๐—ถ๐—ป๐—ด ๐—ฌ๐—ผ๐˜‚๐—ฟ .๐—ก๐—˜๐—ง ๐—ค๐˜‚๐—ฒ๐—ฟ๐˜† ๐—ฃ๐—ฒ๐—ฟ๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐—ป๐—ฐ๐—ฒ ๐˜„๐—ถ๐˜๐—ต .๐—”๐˜€๐—ฆ๐—ฝ๐—น๐—ถ๐˜๐—ค๐˜‚๐—ฒ๐—ฟ๐˜†() ๐Ÿš€

๐—•๐—ผ๐—ผ๐˜€๐˜๐—ถ๐—ป๐—ด ๐—ฌ๐—ผ๐˜‚๐—ฟ .๐—ก๐—˜๐—ง ๐—ค๐˜‚๐—ฒ๐—ฟ๐˜† ๐—ฃ๐—ฒ๐—ฟ๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐—ป๐—ฐ๐—ฒ ๐˜„๐—ถ๐˜๐—ต .๐—”๐˜€๐—ฆ๐—ฝ๐—น๐—ถ๐˜๐—ค๐˜‚๐—ฒ๐—ฟ๐˜†() ๐Ÿš€

If youโ€™ve ever watched an EF Core query crawl to a halt trying to load tons of related data at once, Iโ€™ve got great news: .๐—”๐˜€๐—ฆ๐—ฝ๐—น๐—ถ๐˜๐—ค๐˜‚๐—ฒ๐—ฟ๐˜†() ๐—ถ๐˜€ ๐—ต๐—ฒ๐—ฟ๐—ฒ ๐˜๐—ผ ๐—ต๐—ฒ๐—น๐—ฝ!

๐—ง๐—ต๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ฏ๐—น๐—ฒ๐—บ: ๐—ข๐—ป๐—ฒ ๐—•๐—ถ๐—ด, ๐—›๐—ฒ๐—ฎ๐˜ƒ๐˜† ๐—ค๐˜‚๐—ฒ๐—ฟ๐˜† ๐Ÿ—๏ธ By default, EF Core tries to fetch all related data in a single, massive query when you use .๐˜๐˜ฏ๐˜ค๐˜ญ๐˜ถ๐˜ฅ๐˜ฆ(). Itโ€™s like attempting to grab every item on your grocery list in one tripโ€”sure, itโ€™s one shot, but it might slow you down if the bag is too heavy!

๐—ง๐—ต๐—ฒ ๐—ฆ๐—ผ๐—น๐˜‚๐˜๐—ถ๐—ผ๐—ป: ๐—ฆ๐—ฝ๐—น๐—ถ๐˜๐˜๐—ถ๐—ป๐—ด ๐—œ๐˜ ๐—จ๐—ฝ! โœ‚๏ธ .๐˜ˆ๐˜ด๐˜š๐˜ฑ๐˜ญ๐˜ช๐˜ต๐˜˜๐˜ถ๐˜ฆ๐˜ณ๐˜บ() breaks that one giant query into multiple, smaller queries. That means: ๐—™๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ฒ๐—ฟ๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐—ป๐—ฐ๐—ฒ: Smaller queries tend to run more quickly. ๐—Ÿ๐—ฒ๐˜€๐˜€ ๐— ๐—ฒ๐—บ๐—ผ๐—ฟ๐˜† ๐—จ๐˜€๐—ฎ๐—ด๐—ฒ: No more dealing with huge result sets all at once. ๐—˜๐—ฎ๐˜€๐—ถ๐—ฒ๐—ฟ ๐——๐—ฒ๐—ฏ๐˜‚๐—ด๐—ด๐—ถ๐—ป๐—ด: Multiple simpler queries are easier to understand and optimize.

See It in Action! ๐Ÿ‘€

Check out the carousel to compare the code and the resulting SQL outputs. Youโ€™ll see:

Before .๐˜ˆ๐˜ด๐˜š๐˜ฑ๐˜ญ๐˜ช๐˜ต๐˜˜๐˜ถ๐˜ฆ๐˜ณ๐˜บ(): One giant query trying to return everything at once. After .๐˜ˆ๐˜ด๐˜š๐˜ฑ๐˜ญ๐˜ช๐˜ต๐˜˜๐˜ถ๐˜ฆ๐˜ณ๐˜บ(): Multiple, leaner queries that fetch data in smaller chunks.

By moving through the images in the carousel, youโ€™ll spot the difference in both the C# code and the underlying SQL. Itโ€™s a clear illustration of how .๐˜ˆ๐˜ด๐˜š๐˜ฑ๐˜ญ๐˜ช๐˜ต๐˜˜๐˜ถ๐˜ฆ๐˜ณ๐˜บ() can turn a performance bottleneck into a breeze!

๐—ช๐—ต๐—ฒ๐—ป ๐—ฆ๐—ต๐—ผ๐˜‚๐—น๐—ฑ ๐—ฌ๐—ผ๐˜‚ ๐—จ๐˜€๐—ฒ ๐—œ๐˜? If your EF Core queries feel slow or bloated, give .๐˜ˆ๐˜ด๐˜š๐˜ฑ๐˜ญ๐˜ช๐˜ต๐˜˜๐˜ถ๐˜ฆ๐˜ณ๐˜บ() a try. Itโ€™s a quick fix that can bring a big boost in responsivenessโ€”no more struggling under the weight of giant queries!

In a nutshell: .๐˜ˆ๐˜ด๐˜š๐˜ฑ๐˜ญ๐˜ช๐˜ต๐˜˜๐˜ถ๐˜ฆ๐˜ณ๐˜บ() makes your queries leaner, faster, and easier to manage. โœจ

View on Linkedin

linkedin ยทgithub
Copyright ยฉ 2025 Igor Carvalho
contact@ayresigo.dev
Powered by Urara