Перейти к содержимому

Stop Running EF Core Queries One-By-One (Do This Instead)

Milan Jovanović

0:00 / 0:00

Stop Running EF Core Queries One-By-One (Do This Instead)

29 057 просмотров · 8 месяцев назад
Milan Jovanović
168 тыс. подписчиков
29 057 просмотров · 8 месяцев назад
Want to master Clean Architecture? Go here: https://bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: https://bit.ly/3SXlzSt 🚀 Want a real performance boost in EF Core? A common API pattern is loading multiple independent datasets in a single request (think dashboards: users + orders + logs). The naïve approach runs queries sequentially… and your latency adds up fast. So you try Task.WhenAll — and EF Core throws the classic error: “A second operation was started on this context…” In this video, I’ll show you the right way to execute EF Core queries concurrently without crashing your app. What you’ll learn Why DbContext can’t run concurrent operations (even with async/await) The dashboard scenario where parallel queries make a big difference How to use IDbContextFactory to create a separate DbContext per query A clean helper pattern to keep query code reusable How to verify concurrency with tracing + measure the win Tradeoffs to consider (more contexts, more connections) DbContext is Not Thread-Safe: Parallelizing EF Core Queries the Right Way https://www.milanjovanovic.tech/blog/... Check out my courses: https://www.milanjovanovic.tech/courses Read my Blog here: https://www.milanjovanovic.tech/blog Join my weekly .NET newsletter: https://www.milanjovanovic.tech Chapters