How To Optimize EF Core Query Performance With Compiled Queries

preview_player
Показать описание

EF Core is an amazing library to work with in .NET. It's become blazing fast in the latest versions, but there are ways to make it even faster. One feature to make EF Core faster using Compiled Queries. This is a rarely used EF feature, and for good reason, but I'll still show you how you can apply it.

Unleash EF Core Performance With Compiled Queries

Join my weekly .NET newsletter:

Read my Blog here:

Subscribe for more:

Chapters
0:00 How to create a Compiled Query
4:02 Benchmarking a simple Compiled Query
5:33 How to create a no-tracking Compiled Query
7:35 How to create an asynchronous Compiled Query
Рекомендации по теме
Комментарии
Автор

Love your informative videos man. Much appreciated

bloopers
Автор

Awesome content! You're the best Milan.

kodindoyannick
Автор

Hi, such a nice and easy way to explain all what you know about EF and how it works! Thanks a lot.

joseagustincarrenogallego
Автор

Axaxaxa Preview 😮 TOP content bro you are awesome 💯!

nouchance
Автор

Wish I could give you 2 thumbs up. One for detailing exactly how to do it, the other for delving into the performance difference so I already know what to expect. Well done sir.

mikewiebel
Автор

Thanks for sharing this bit of optimization

nove
Автор

Thanks for this new piece of information it will be really helpful and i read about in your newsletter as well on Sunday. Just a request from a beginner can you make videos for beginners as well like from basic (more kind of a tutorial)

tarunpahilajani
Автор

Very informative, as usual. Can we expect 'EF: zero to hero' series?

bugadada
Автор

Is DbContext creation inside a benchmark so insignificant that it is ok have it there? Not sure how much of internal logic is reused with new operator in contrast with pooling contexts.

greatpowerplay
Автор

What is better in terms of performance for simple select queries with few filters (2 props lets say). Compiled Async Queries ? Or using ef methods like SqlQuery, FromSql ?

karolg
Автор

thanks a lot Milan for that awesome video 👍.
how to create compiled queries in Clean Architecture and I can only access IApplicationDbContext in the Application layer and not ApplicationDbContext which in the Infrastructure layer?

Tamer_Ali
Автор

You’ve talked briefly about the compiled query caching, but if I’m right, that means if I ran the “NotCompiled” version of the query more than once in my application lifetime, the difference in performance would be significantly less, correct ?

Nismifor
Автор

I enjoyed this video, thank you. As someone who moved away from EF back when it was EF5 to ADO (for performance reasons), I'm now exploring moving back to EF Core as the team has done a great job with performance over the years. ADO is faster, but it's less of a different and EF has lots of benfefits. I have one question though, and wondered if I'm missing something obvious. When you wrote the Async Compiled Query, why did you use FirstOrDefault rather than FirstOrDefaultAsync?

jonbellamy
Автор

Is it possible to use CompileAsyncQuery for Add and Update? Or only for Get ?

I-PixALbI-I
Автор

I don't get it work with table-joins (Linq: include() an List-Property in DbSet, which contains items from 2nd table).

rs
Автор

Hello, could you describe why you are using context.Set<entity>, and not using context.entity?

gorVerbinsky
Автор

Nice video. What about an IAsyncEnumerable?

renzors
Автор

Why are you create DbContext inside benchmark method?
In that case you also measure DbContext creation and connection opening instead of measuring just difference between compiled and usual version.

tvrkfjo
Автор

How much does the construction of the DbContext cost. That is a common cost in both tests, if that is significant then the performance improvement is better than what you have stated. OTH if its not significant it might have been worth mentioning to keep that clear

Other considerations are application start time. Compiling a single simple query may not be that significant but what about a system with a large number of complex queries. Using some lazy approach that compiles and caches the query on demand IMO wouldn't' be hard though.

codingbloke
Автор

Is it better to collect related compiled queries in a repository related to their entity then inject the repository when needed or place them in DbContext?

Tamer_Ali