5 EF Performance Tips You NEED to Know + BENCHMARKS

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

EF Core is awesome, right? If you're a .NET developer, you will probably agree. But EF Core is just another tool. You need to know how to use it properly. In this video, I'll show you 5 ways to improve performance with EF Core. I'm also including benchmarks for each example so you can see the performance difference. This will be a very educational video on EF Core, with some surprising findings.

5 Awesome C# Refactoring Tips

Join my weekly .NET newsletter:

Read my Blog here:

Chapters
0:00 1 - Tracking vs No Tracking Query
1:58 2 - Select fewer columns
6:08 3 - Implicit vs Explicit Include
8:26 4 - Split queries
11:01 5 - Naive vs Offset Pagination
Рекомендации по теме
Комментарии
Автор

Hello Milan! I would like to tell you about pagination that works in 1 millisecond even on 100 million lines, and it doesn’t matter what offset you have. The bottom line is that you create an asc or desc index (ideally primary) and select order by column Take(PageSize). Next, if you need the next or previous page, then you take the Max or Min value from the current page. Then create a query like where c >= value order by value ascending Take(PageSize) or where c <= value order by value descending Take(PageSize) depending on what you want next or previous pages.

iteospace
Автор

I really like the implicit and explicit session in this video. All my doubts were cleared here. Thanks, a lot.

taiphanvan
Автор

As always in Your videos, You're going straight to the point and explain nuances behind the code whilst coding live with simple to understand, yet comprehensive examples. I absolutely love Your videos! Keep up the good work!

macioazz
Автор

Thank you for creating this useful content again, Milan ☺👏

wendysanarwanto
Автор

Didn't know about the SplitQueries, time to refactor some endpoints, thanks Milan

mstarlingc
Автор

Really thank you <3. The last case is the problem I'm having and this video helped me improve it.

RinkaMizuki
Автор

Hi Milan,
Thanks for the amazing great work for the insightful content.

I do have a question regarding a concept you discussed at .

As I understand it, implicit and explicit include are analogous to lazy and eager loading, respectively. In eager loading (achieved by explicit include), when, for example, querying 100 sales items, all the related data gets loaded in a single query, optimizing performance. However, with implicit include, Entity Framework makes an additional query for each item, resulting in the N+1 query problem – for 100 sales items, it would result in 1 query for the sales items and 100 additional queries for their related entities, causing inefficiencies.

In summary:
With .Include(s => s.SalesPerson): 1 query
Without .Include(s => s.SalesPerson): 1 query for Sales + 100 queries for SalesPerson (triggered lazily) = 101 queries

Could you please confirm if my understanding is right?

satishsathishsati
Автор

Nice, yet another great video, thank you

djaalabahmed
Автор

Thank you, Milan. Can you tell me the difference between sql statements when using a split query in your example?

OmarMicano
Автор

May I know what theme you are using? Thank you

kevintuan
Автор

hi Milan, what do mean when you say "projection to a DTO"? Thanks

kenjohnsiosan
Автор

I absolutely love this video. I have a suggestion, dont You think it would be really cool if You do playlists, like "Everything you need for becoming a junior/mid/senior" developer? Some of your videos are really begginers friendly, but some of them like advanced ddd concepts are not prolly needed to learn to become junior. That would be great improvement of your channel and Im sure I'd get You more watch time, views, students and patreons!

arteqppp
Автор

Could you pls talk about Saga pattern with and without orchestration?

chuannguyen
Автор

This video could not have come at a better time, I am refactoring some legacy queries within my companies codebase rn.

willgale
Автор

I can't find a logical explanation to why implicit including is slightly faster than explicit including. Maybe something to do with the massaging phase where EF Core only needs to traverse the expression tree for implicit properties?

DotNetFun
Автор

Hi Milan, great video!
Does it make difference where you write the AsNoTracking in the line, in your case is before the where condition, If I put at the end does it make difference?

alfonsdeda
Автор

The Split query actually makes only one roundtrip. It makes two selects but in a single SQL query. If it sent it in two queries, it wouldn't been faster than the first one.

homeropata
Автор

I think you forgot to mention compiled queries.

Brodeon