Тёмный
No video :(

Making Entity Framework Core As Fast As Dapper 

Nick Chapsas
Подписаться 300 тыс.
Просмотров 86 тыс.
50% 1

Check out my courses: dometrain.com
Become a Patreon and get source code access: / nickchapsas
Hello, everybody, I'm Nick, and in this video, I will show you how you can use Entity Framework Core's Compiled Queries to achieve very similar performance to Dapper. This technique optimizes both speed and memory; the results are remarkable.
Workshops: bit.ly/nickwor...
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: bit.ly/ChapsasG...
Follow me on Twitter: bit.ly/ChapsasT...
Connect on LinkedIn: bit.ly/ChapsasL...
Keep coding merch: keepcoding.shop
#csharp #dotnet

Опубликовано:

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 224   
@sirmaelstrom8080
@sirmaelstrom8080 Год назад
It would be really valuable imho to see more complicated examples, not just for performance reasons but because I'm just very curious about how more complexity might change any of your approaches or design considerations in something that is closer to real world scenarios. Sometimes I come away from the videos and courses learning a lot, but not necessarily seeing how my design could really look like in a larger picture.
@ryansessions6278
@ryansessions6278 11 месяцев назад
Agreed...him advocating for FirstOrDefault over SingleOrDefault because of the difference between looking up 2 records versus 1, is saying "don't worry about logical errors...we want another 1 microsecond of performance!"
@NickMarcha
@NickMarcha 3 месяца назад
I'm particularly interested if this approach is feasible in a filtered pagination scenario. If it's not, it would seem to have a limited use case for scenarios where performance would seem to matter more.
@danielgilleland8611
@danielgilleland8611 Год назад
Yes, a follow-up video of more complex queries would be helpful, as it will paint a clearer picture for those looking to choose between Dapper & EF Core.
@snapman218
@snapman218 Год назад
The fact that EF doesn't automatically do AOT compile for queries is really astonishing.
@sacamp8952
@sacamp8952 10 месяцев назад
My exact thought. I just assumed this happened under the hood by default.
@AKA-077
@AKA-077 Месяц назад
that would take more memory so idk why it needed to be done automatically
@andersborum9267
@andersborum9267 Год назад
As compiled queries were readily available in LINQ to SQL, it's interesting to see developers on EF Core disregarding the use of compiled queries (nor even questioning whether it exists at all, leaving valuable CPU cycles on the floor). Basically, all it takes is curiosity and peeking at the mechanism that translates C# based LINQ queries to SQL, and the subsequent materialization of data to typed objects. That path should lead to questions on whether the continuous translation could be omitted (i.e. cached, parameterized), and thus end with the discovery of compiled queries. As a freelance consultant, absence of compiled queries on contracted projects are usually the norm, and it's usually a quick win to implement. Disclaimer: compiled queries are more heavy during application start-up, obviously, as the expression tree needs to be evaluated and translated, but they're clear winners for the majority of applications that are online for hours or days on end. Nick mentions this as well, but given the amount of memory available to app domains these days, compiled queries should be the default approach imo.
@someman7
@someman7 Год назад
They could make it a setting too. So you could have runtime queries while developing, compiled queries in production (assuming no weird discrepancies between the two)
@gbjbaanb
@gbjbaanb Год назад
Or use dapper and its even faster. And simpler. And uses less memory. And quicker to startup. And easier to understand the queries that are used to call the DB, no surprises in the generated sql.
@user-qp8bt7gq4b
@user-qp8bt7gq4b Год назад
​@@gbjbaanb I am a Junior developer and I can't understand how you even can able to use Dapper in a real project... For example, you have to update an entity with some many-to-many relationship. How should I implement the Update() method in my repository? For now I just delete all records in link-table and then create them all again. How it can be faster then EF Core? EF Core see that you for example delete one item from the collection property and add one item. And it generates the appropriate sql query. Or, even simpler example. Let's forget about many-to-many. Just a simple Update() for a small model. With Dapper you will write the SQL code that updates all the fields. EF Core will update only one field. I am sure that I am wrong somewhere and maybe my question is even some kind of stupid, but can you explain it to me please? Grats!
@sneer0101
@sneer0101 Год назад
​@@gbjbaanb Yep. Dapper is much better and you have complete control over optimisation
@NickSteffen
@NickSteffen Год назад
@@user-qp8bt7gq4b EF Core translates to the same t-sql language you use in dapper when executing queries. So anything you do in ef core can be done in Dapper you just need to look at the output query EF core produces.
@amrosamy8232
@amrosamy8232 Год назад
EF core 8 now supports query execution and directly maps the results to VM or Dto such as dapper
@manishmayekar1103
@manishmayekar1103 Год назад
Hi, Can you make scenario where stored procedure from database side is integrated into Entity Framework
@LoganDunning
@LoganDunning Год назад
Ef core power tools visual studio extension
@trumpetpunk42
@trumpetpunk42 Год назад
Are you asking how to do it? Or if there's a similar performance overhead to be fixed?
@dcuccia
@dcuccia Год назад
Nick, this is excellent content, thank you. This feature gives me the best of both worlds - the convenience and feature set of EF core, and the performance where it's needed. Also interested in your thoughts on the new EF Core 8 raw SQL queries for unmapped types, in the same context of opt-in for squeezing performance, and what the limitations or gotchas are. Thanks!
@GachiMayhem
@GachiMayhem Год назад
Very good, thanks Nick! Now waiting for AsNoTracking() explanation)
@mikeinsch8356
@mikeinsch8356 Год назад
Would be interested in your take on options such as lazy instantiating of compiled queries so that you defer the hit on performance from startup to first use, and on using in-memory caching and cache expiration of queries in cases where they might be used in bursts but then not be required again for some time, to help control memory footprint in large / long lived apps.
@stoic7810
@stoic7810 Год назад
Lazy loading ... eish, I always fall for that trap, then I remove it :) If you manage all the code, then Lazy is fine, but someone always iterates a list somewhere, and they love the fact that the nested references are loaded via lazy loading .... until they run it with real data. where there is more than two records :) But yeah, I've never tried Compiled Queries with LazyLoading. Might be wrong, but i think it will cause havoc if there are circular references in you poco classes
@petrusion2827
@petrusion2827 Год назад
@@stoic7810 I don't think Mike Insch meant Lazy Loading of entities. I think he meant to use Lazy for compiled queries instead of Func
@PelFox
@PelFox Год назад
​@@stoic7810 Yes, Lazy wont create the instance until it's called the first time, so it wont be as big impact on your startup time.
@alexandregiaccheri
@alexandregiaccheri Год назад
I'd love to see some examples of more complex expressions with benchmarks!
@DiomedesDominguez
@DiomedesDominguez Год назад
In 2013 I needed to used compiled queries for a Windows Phone application, something like you did to cache the queries to a local database. I'm glad to see them again in the wild.
@logank.70
@logank.70 Год назад
Personal opinion on this kind of subject is that if you have the experience to know when something like compiled queries is necessary then go for it. Otherwise I tend to go with the "it isn't a performance issue until it is one." If something becomes a performance bottleneck for one reason or another then use a profiler to find where it is, diagnose the root cause, and then optimize for your needs. I just ran into this one in a project I'm helping with where they were rending ~150 (at most) extremely simple polygons (7 or 8 points at most). I wrote a conversion function that would give you the polygon when you asked for it. In areas of the program that needed a polygon I would ask for one and do with it what I needed. Performance was perceptively instantaneous and memory usage was well within acceptable parameters. The argument was around the idea of "we should cache it on the way in so it is calculated and created once at most. It'll perform better that way." I benchmarked it (with DotnetBenchmark of course) and doing the operation that produced a polygon 3x as complicated than needed an insane number of times (they would never get close to) the results were 7.4ms and 10MB of heap allocation. In some contexts that is insanely slow. In this particular context it is insanely fast. Unfortunately it was multiple days worth of discussion even after I shared my results. I'll never get that time back that everyone could've spent doing more productive things. TL;DR If your experience tells you this is the right time to do something more performant have at it. If you don't have the experience then focus more on how clear your intent is being expressed. Sometimes code that is easier to read and understand is worth more than code that executes faster. To steal a quote I read from someone somewhere on RU-vid "if your code doesn't work I don't care how fast it doesn't work."
@proosee
@proosee Год назад
Yup, you are absolutely right. In fact, the very reason people use Dapper is not query compilation time - it's that EF sometimes does bad job when translating LINQ to SQL for complicated queries. And I hear people say: "well, you can guide EF to do better job" - and that's true in most cases, I can spend couple hours or even days trying to "guide EF" or I can write SQL query in 15 minutes, but who would want to do that, right?
@jonashabel2052
@jonashabel2052 2 месяца назад
Please a video where you compare dapper and ef core with complext sql queries (joins and stuff). Nice video ! I love it.
@RasmusFjord
@RasmusFjord Год назад
Dear Nick, i love your videos and just became a patreon because of this. I love these small videoes with ready to use stuff, 1 focus, which makes it easier to implement on an every day to day basis! Thanks for your content!
@KristianVerwold
@KristianVerwold Год назад
@Nick Chapsas , would it make a difference to use FromSql(), FromSqlRaw() from EF ? While using native SQL for Dapper, it would be nice to see, how FromSql() performs from EF, excluding all LINQ
@briumphbimbles
@briumphbimbles Год назад
Yep thats pretty much what I asked last time
@nickchapsas
@nickchapsas Год назад
Next EF video will cover this
@PelFox
@PelFox Год назад
EF core 8 preview has sql unmapped types, pretty much how Dapper does it. With that you won't even need Dapper.
@briumphbimbles
@briumphbimbles Год назад
@@PelFox Well thats really the question. If EF can do everything dapper can do and if when compared like for like its as performance or out performs it and is nearly as performant when you use it with a bunch of quality of life improvements then really, what is the point of Dapper?
@osman3404
@osman3404 Год назад
How about FromSql but also compiled?
@franciscovilches6839
@franciscovilches6839 Год назад
My team keeps track of the top slowest queries. Another great tool to have under our belt to optimize these.
@valentinnikolov2474
@valentinnikolov2474 Год назад
Nick, continue with those videos. They are super interesting. Thanks for debugging it. You are a star!
@RichHeart89
@RichHeart89 Год назад
Sounds like the expanded video about optimizing more complicated queries with lots of joints and counts and the like would be exactly what I have been looking for 😅
@GlassScissors
@GlassScissors Год назад
Hi Nick, thank you for the Benchmarks! Great information as always :) Please make a video on more complex queries. Take care and enjoy the Easter Holidays.
@DemoBytom
@DemoBytom Год назад
How do I pass the CancellationToken to the compiled query? Since the lambdas inside use synchronous methods I cannot simply pass the CT there. How can I pass one, and ensure the query is still cancellable?
@RaZziaN1
@RaZziaN1 11 месяцев назад
Why would u add cancellationToken if it's not async ?
@expertreviews1112
@expertreviews1112 Год назад
top drawer video... A big YES for follow-up video of more complex queries like joins etc... Once again you're putting out awesome content Nick!!!! My fav RU-vidr and trainer
@marcelotieghi936
@marcelotieghi936 6 месяцев назад
I just subscribed to your channel, really enjoying your videos because you seem to emphasize application performance, something I highly value. I'm new to the field and have a lot to learn. I don't want to be offensive, as English is not my first language, but if possible, could you speak a bit slower? It's not your speech, it's just me being a bit slow, hahahah. But your content is great!
@snapching
@snapching Год назад
If I understand Dapper correctly, I would point out that in Dapper you have the SQL as a magic string. Rarely would this be limited to one line. If it was more complex, it would then likely move to a stored procedures. Which would then likely bleed in business logic with a stored procedure...not a good practice anymore (IMO). In addition, if an update gets involved, we now need a multi table transaction. What would be interesting is a comparison of Dapper and efcore in terms of a more complex db structure. I respect your speed argument, but a few milliseconds here and there are not as costly as a developer with bad coding practices.
@nickchapsas
@nickchapsas Год назад
Not every big string is a magic string. Especially with IDEs like Rider, I can use Raw String Literals and I have full syntax highliting of the query with checks on per-engine syntax. This is the best case scenario for EF. It only gets worse from here.
@gbjbaanb
@gbjbaanb Год назад
Imho sprocs are the best practice. Put all your sql into sprocs and then treat the db as an API. It requires more discipline from coders though, which is why it's considered bad practice 😅. It's also easy now securable as you can prevent arbitrary access to tables so if a hacker ever got access, they can download your entire user table with a single query. Not so if you only use sprocs.
@snapching
@snapching Год назад
@@nickchapsas IMO - A string is within the code base that expresses a SQL statement is NOT a good place for a SQL statement. Its a string that contains a statement that a SQL processor has to interpret. Adding IDE assistance in the creation of the string (especially when its relational) means it has to understand the schema to be of assistance, which i feel adds additional coupling (it needs a connection string to do that). SQL statement as strings IMO is just not a good idea from a maintenance perspective. It leads to concatenation to create a SQL string that will select or filter the data as required. I feel that is not falling into the pit of success, but really poor code. Many developers simply want a tabular dataset, and throw the SQL at the engine. Millions and millions of dollars have been spent how to optimize a query. Using procedural logic to first limit the dataset , and deal with a subset, is an effective way to reduce the load on the data engine (regardless if its relational or otherwise). Using a stored procedure is also known to be an issue when it contains business logic. Data retrieval and storage need more thought, and IMO a SQL statement in code isn't something that cuts it for me.
@sneer0101
@sneer0101 Год назад
​@@snapching I think a lot of your gripes seem to come from your own bad practices to be honest.
@stevenras
@stevenras Год назад
@@gbjbaanb - If all you’re considering is performance then I agree with you. When you look at it from a maintenance, testing, CI/CD, and technical expertise standpoint then it quickly becomes untenable. I worked on a project that had over 500 stored procs and updating a stored proc was a nightmare. Changing the shape was nigh impossible because there was no real way to determine who was consuming it and whether they would be affected by your change. What you end up doing is making a new sproc with your slightly different requirements and so you end up maintaining multiple versions of essentially the same thing. Sooooo glad to be off that project 😅
@Shadow_Play3r
@Shadow_Play3r Год назад
Amazing video as always Nick. In past we moved project from EF to sql procedures (this required lot of business logic rework). Performance hit was huge from EF for us, but good to know of things keep improving from EF Core.
@VitalyPavluk
@VitalyPavluk Год назад
Nice !!! Please keep continue with series of EF vs Dapper! I use EF alot but still don't know all its perf aspects thank you
@barmetler
@barmetler Год назад
I would absolutely love to see examples with relations
@MatthewCrawford
@MatthewCrawford Год назад
Looks like an awesome addition to make to the EF repository wrapper
@jogibear9988
@jogibear9988 Год назад
Could you also Test linq2db against both? It claims to be one of the fastest ORM Mapper.
@przemysawukawski4741
@przemysawukawski4741 Год назад
IT would be great to see this. Also Linq2Db can be used together with EF Core as a synergy where it gives you possibilities to use all the features from both ORMs, which is just fantastic.
@TimmyBraun
@TimmyBraun Год назад
linq2db is great!
@tonydrake462
@tonydrake462 Год назад
please - more videos on this... brilliant
@isachellstrom8467
@isachellstrom8467 Год назад
Test with even more and bigger advanced queries please. Love you and your content! also very intrigued about ef vs dapper in medium to large applications.
@ocnah
@ocnah Год назад
Didn't know about compiled queries, please do the video about the more complex scenario's!
@paulecampbell
@paulecampbell Год назад
hi Nick, this is the comment you told me to leave down below
@jarjarbinks4908
@jarjarbinks4908 Год назад
I want see more videos about that! Love your content Nick!
@martinhjalmarsson2444
@martinhjalmarsson2444 Год назад
Isn't precompiled queries only for speeding up the first time you do that query? When not using precompiled queries it is compiled and cached the first time and then subsequent queries will be fast. Or am I wrong?
@Passta357
@Passta357 Год назад
great point, I asked myself the same question
@Yupmoh
@Yupmoh Год назад
Wondering about this too
@amirhosseinahmadi3706
@amirhosseinahmadi3706 Год назад
The difference is that without compiled queries, even after EF caches the compilation result (i.e. the SQL), each time you send it the same query, it still has to traverse and examine the expression tree in order to determine whether or not a cache entry exists for that particular expression tree. With compiled queries, on the other hand, this step is eliminated.
@martinhjalmarsson2444
@martinhjalmarsson2444 Год назад
​@@amirhosseinahmadi3706 thanks for the answer! So that is why we see the difference in the benchmarks.
@vmakharashvili
@vmakharashvili Год назад
Awesome! I didn't know that.
@ThrottleScotty
@ThrottleScotty Год назад
Super interesting and useful info - thanks for this and all your other content!
@ricardomlourenco
@ricardomlourenco Год назад
Awesome video. We definitely need the more complex scenarios. Also can you create a comparison calling a Stored Procedure?
@PanzerFaustFurious
@PanzerFaustFurious Год назад
another reason why i wish methods has static fields or something similair
@syndicatedshannon
@syndicatedshannon Год назад
.First is suspect, in the context used by Nick. If you know there will be one result, limit 2 will return the same number of records. If that is enforced by constraint, then the query will typically scan the same row count. If not enforced, then .Single is essential. The specifics are relevant, but don't go replacing all your method calls for performance.
@Alex-fj2xu
@Alex-fj2xu 10 месяцев назад
I'm probably missing something, but as per benchmarks you may benefit from compilation even when doing it in the same method, right before executing.
@deansimonelli2230
@deansimonelli2230 Год назад
Would using .AsNoTracking improve performance even further?
@nickchapsas
@nickchapsas Год назад
In these tests it would actually make it worse. Check this video for more details: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Q4LtKa_HTHU.html
@deansimonelli2230
@deansimonelli2230 Год назад
@@nickchapsas Interesting, Microsoft says "They're quicker to execute". Common sense would think so too. I am curious now why there are no performance gains.
@Petoj87
@Petoj87 Год назад
​@@nickchapsas does that video combine no tracking with compiled queries?
@tehsimo
@tehsimo Год назад
I always learn something from these videos
@pquesadacr
@pquesadacr Год назад
Wow Nick, I loved this video! Thanks a lot...
@Kerbiter
@Kerbiter Год назад
Would be interesting to see Linq2DB performance comparison/walkthrough also.
@glennwatson
@glennwatson 10 месяцев назад
I would personally not put async on methods that just return the Task. Eg the EF_Single_Compiled(). Just skips the whole state machine. Might change the performance slightly.
@user-lm9jm9ql1t
@user-lm9jm9ql1t Год назад
Also you could show some samples of how to refactor classic existing scoped services from DAL (repositories etc) to support compiled queries. That would be great!
@atlesmelvr1997
@atlesmelvr1997 Год назад
Did you forget to set it default asnontracking? There is a good performance boost using that with EF
@nickchapsas
@nickchapsas Год назад
Asnotracking would make it slower. Check the previous EF vs Dapper video for more details
@joelqrq
@joelqrq Год назад
Would love to see a video on Expressions with EF Core
@PelFox
@PelFox Год назад
Interesting. But still, its microseconds difference using raw sql spaghetti vs strongly typed LINQ. I would pick EF anyday and use raw sql only when it's absolute necessary.
@hadiboukdir386
@hadiboukdir386 Год назад
Hi Nick, Thanks for the video, can you please make a more complicated example video with joins...
@warrendemars
@warrendemars Год назад
One item you didn't cover is adding "AsNoTracking()" on the EF call. [Pardon if covered in a prior video.] I've found this made a significant different in my EF routines when I know I don't need to do any updates on the returned data.
@nickchapsas
@nickchapsas Год назад
I covered it in a previous video. It would have made the operation slower here.
@joseluisguerrainfante5036
@joseluisguerrainfante5036 Год назад
Awesome tips, thanks!
@Endomorphism
@Endomorphism Год назад
we can complie it on demond and cache it, even to save memory cache could have an expiration criteria 🙂
@user-ys6nh6fe5o
@user-ys6nh6fe5o Год назад
nice, and we need more ef stuff
@10199able
@10199able Год назад
I wonder if EF cache expressions? So if you call _context.Movies.FirstOrDefault... it will eat some memory & time for the first execution, but does EF need to do it every single call afterwards?
@javorrrful
@javorrrful 7 месяцев назад
Great video but does it worth the effort ? In my projects I just combine them - EF Core is great for Save operations and simple queries and Dapper for Stored procedures (mainly complicated read opperations). I checked to see that this is a practice in many other projects and fiths well in the CQRS pattern. Even if you make EF Core faster - there are some restircitions how stored procedure can be executed, you don't really need to loose time with this.
@michi1106
@michi1106 3 месяца назад
I didn't know Dapper, so in comparison. Does Dapper also use static queries like the pre-compile. For me it's make a big difference, if the queries stayed for ever. So for a web-application, not rly useful or better, use it with all respect .
@stoic7810
@stoic7810 Год назад
It just doesn't make sense to create a compiled query for every query you want as fast as dapper. It just makes the code so much more complicated for other users. I've been a long time EF Core user, and a recent converter to dapper (3 or so years now) When I was using EF I used compiled queries, and when I really wanted to make things faster in EF I used stored procs. If I want to churn out an app fast I use EF Core for Insert, Update, Delete ... and dapper for Read. If I want a performant application with human readable code I use Dapper. ... and if I wanted to annoy everyone I used readers and writers :)
@suatogos
@suatogos 11 месяцев назад
Thanks a lot 🎉❤
@iliqngorki3310
@iliqngorki3310 Год назад
Hello @Nick Chapsas I have one question public static class OneEntityCompiledQuery where TEntity : class { public static readonly Func FirstOrDefaultAsync = EF.CompileAsyncQuery((DbContext context, Expression predicate) => context .Set() .AsNoTracking() .FirstOrDefault(predicate) ); } Can I do something like this for more generic use of the CompiledQueries? To pass the where expression as a parameter ?
@majidmajid2192
@majidmajid2192 Год назад
This is very cool feature and in my opinion, that allocated memory is nothing for achieving that performance. One of my question about this video is: How it fit in specification pattern and DDD? I think we should put our specifications in infrastructure layer. any idea about that?
@MatheusHenrique-ji5sv
@MatheusHenrique-ji5sv Год назад
why should i use Find() for querying with primary keys instead of First/Single?
@Zeeshan-uj6cx
@Zeeshan-uj6cx 3 месяца назад
It is valuable addon info to me
@diogenesdirkx
@diogenesdirkx Год назад
Hey, this is not an AsNoTracking query, so it's not a fair comparison since Dapper doesn't have a tracking feature. EF Core should be used with AsNoTracking option enabled, as it can be resource-intensive and use reflection, which can have a heavy impact on performance.
@nickchapsas
@nickchapsas Год назад
AsNoTracking would have made EF slower. Check the last EF video for more details
@corblimey8729
@corblimey8729 Год назад
I would like to see speed test generic base repository with derived repository for more complex linq, vs pure dbcontext only
@pilotboba
@pilotboba Год назад
I'm curious what Benchmark is doing. It's my understanding that EF Core has a query cache, and if they see the same query they will reuse it hence saving the compile time. I think they also have, or will have a way to compile the queries at build time and they are cached in a DLL. I've never seen the need for these optimizations. But it's good to know they are there.
@marcelloguimaraes3825
@marcelloguimaraes3825 Год назад
Please make a video about more complicated scenarios, Nick
@RockTheCage55
@RockTheCage55 Год назад
More Complex scenario please :)
@goose1923
@goose1923 9 месяцев назад
Why don't you use the EF Core AsNoTracking extension method? Is this implied since it is a ATO compiled query?
@bengi8406
@bengi8406 Год назад
Hi Nick, great video but you still owe us the explanation why AsNoTracking() did poor in the previous video :P
@MagicCPM
@MagicCPM Год назад
May you try to just add MemoryCache? If I remember well, if EF founds MemoryCache in DI, it will use it to cache the compiled query (so you shoudn't use pre-compiled functions).
@Ronaldoroot
@Ronaldoroot Год назад
Great video, thanks
@ArnonDanon
@ArnonDanon Год назад
If you dont control the db structure, lets say different team will be incharge of db and how the db model evolve and you still need to access the db writing different complex query from moultiple tables inculding update and inserts based on those queries would you still go with EF/Dapper way or choose lower level such Oracle.ManagedDataAccess incase of oracke db?
@dcvsling
@dcvsling Год назад
yes plz, explain it, and how hard to said compiled query is translate linq like script to sql as same as you directly write it , then cache and reuse it ?
@AAAnatoly
@AAAnatoly Год назад
Didn't understand how to use asynchronous with this feature. I Try to write something like EF.CompileAsyncQuery((context, id, cancelationToken) => ...ToList()). But cancellation doesn't work (logic - i didn't use it in my lambda). On the other hand i can do EF.CompileQuery((args) => ...ToListAsync(cancellationToken)). But i do not understand how to right
@prasannahiremath1672
@prasannahiremath1672 Год назад
Can I implement order by with EF.CompileAsyncQuery ?
@Razeri
@Razeri Год назад
Why ef just not store cache of compiled functions at background then? it will be much more usefull than write compile for each fync
@zoiobnu
@zoiobnu Год назад
Maybe you can show a video using Compiled Queries with Cancellation Token too
@ahmeddabas
@ahmeddabas Год назад
GREATE VIDEO , PLEASE MAKE A VIDEO DEEP DIVE INTO COMPILED QUERY
@andreymetkiy9052
@andreymetkiy9052 Год назад
Is it possible and necessary to use CancellationToken in such requests(Compile Async request)?
@zagoskintoto
@zagoskintoto Год назад
Wow I didn't know you could do this. I'm thinking whether it's difficult to implement this for when you have a query that may apply certain filters or not depending on the request. Is there a way to chain this compiled queries like returning and IQueryable or it makes no sense?
@I-PixALbI4-I
@I-PixALbI4-I 3 месяца назад
Is it possible to use it with Add/Remove/Update ?
@jinalpatel9154
@jinalpatel9154 Год назад
Informative. Dapper is not tracking the entity as per my knowledge and for EF core it is on by default. What would be the scenario like With Change Tracking , Without Change Tracking, Compiled query and Dapper comparison?
@nickchapsas
@nickchapsas Год назад
No tracking in EF in the current tests will make it slower. Check my previous vs dapper video for more details
@danielxtma
@danielxtma Год назад
That 420 seed got me thinking....
@osman3404
@osman3404 Год назад
In web api, would this compiled queries on ejected to the http methods ?
@mauriciodominguez1833
@mauriciodominguez1833 Год назад
Would it be sensible to use Lazy or AsyncLazy to defer initialization of the compiled queries until they’re requested the first time?
@martinmikhail
@martinmikhail Год назад
I love your videos and you have taught me tons, but this one isn't working for me. In my app, I'm using the unit of work/repository pattern. I created a benchmark app, that pulls in my unit of work to test my linq vs compiled query. My linq query is 2 to 3 times faster and it uses less memory. The query I tested is a simple select with a IN clause in the where. Any idea why?
@lucademarco5969
@lucademarco5969 Год назад
Can compile be used in cases where the query is built at runtime based on filters chosen by the user li,e in search forms? Thanks in advance!
@DevQc70
@DevQc70 Год назад
Nice video Nick 😀 Question for you: Based on my experience with EF Core, the main issue I had was to generate complex reports. When you have to join a lot of tables, do some aggregation, group by and related stuffs. Do you have any good practices to shared with use. Especially when you want to avoid as much as possible stored procedure or plain raw SQL
@gbjbaanb
@gbjbaanb Год назад
I found dapper when s complex join i was trying to implement in EF failed to generate correct sql. It was a bug and might have been fixed by now, but if EF fails like this, then you're SOL. The more complex your queries the greater the chance you'll have to write sql anyway. EF is great for the simple stuff.
@LindenMikus
@LindenMikus Год назад
does dappr not do compiled queries?
Год назад
Nick, Dapper forever! 😁
@Zutraxi
@Zutraxi 5 месяцев назад
As for the memory you carry around with the application in the case of the compiled query, shouldn't be considered. In essence you make compiled quries for actions that you perform often which means it is a lot memory you don't have to now garbage collect multiple times. In an API scenario the query will be called multiple times per second meaning the memory footprint is way better. If you call it once per day then bohoo right?
@fmonteiropt
@fmonteiropt Год назад
Does EF Team have a plausible solution, looks like yes. My impression is that they like to be always behind. Couldn't they make it behind the scenes?
@garcipat
@garcipat Год назад
Does these make more sense in simple or complicated queries or does it depend on the frequency they are executed?
@muhammadtariq8323
@muhammadtariq8323 Год назад
In dapper example, you use result.ToList() Why not cast? (List) result Will it differ performance or memory consumption ?
@nickchapsas
@nickchapsas Год назад
You can’t cast a type down to something that it is not. It needs the ToList to actually enumerate and build the result
@sinus3256
@sinus3256 Год назад
​@@nickchapsas This time it's not exactly true. Since you left "buffered" parameter of .QueryAsync(...) as true (it is a default value), the result you get after 'await' is actualy a List.
@peterhansen8881
@peterhansen8881 Год назад
Great video Nick! Please keep the EF Core vids coming, they are sooo good!
@RobTheQuant
@RobTheQuant Год назад
Nick, could you please benchmark LINQ vs using for loops? doing operations like .Sum, .Where, .Average, .Select, etc...
@xour_yt
@xour_yt Год назад
Are there any drawbacks to using compiled queries besides the issues mentioned in the video?
@flybyw
@flybyw 5 месяцев назад
Is there something similar for MongoDB?
@abdulhabdulroof5215
@abdulhabdulroof5215 Год назад
Nick Complax example please
Далее
Don't throw exceptions in C#. Do this instead
18:13
Просмотров 257 тыс.
How IEnumerable can kill your performance in C#
11:02
Просмотров 116 тыс.
Я ДОСТРОИЛ ЗАВОД - Satisfactory
19:13
Просмотров 170 тыс.
.NET and C# are in trouble. Here is what I'd do.
10:57
NativeAOT for .NET APIs Is Here and It’s INSANE!
14:07
When LINQ Makes You Write Worse .NET Code
9:42
Просмотров 17 тыс.
3 .NET "Best Practices" I Changed My Mind About
10:16
Просмотров 102 тыс.
The New Option and Result Types of C#
15:05
Просмотров 59 тыс.
The Best Way to Validate Your Settings in .NET
18:18
Просмотров 62 тыс.