Do you want to simplify your development process? Grab my free Clean Architecture template here: bit.ly/3Andaly Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@sarathkruthiventy48723 ай бұрын
Hi Milan! When ef core did Cartesian product without split query. .did that minimal api end point also returns 68k rows for that emp id similar to SQL results?
@eugene50963 ай бұрын
100K KZbinr , congrats brother !!!
@MilanJovanovicTech3 ай бұрын
Thank you 🙌
@dusanknezevic90723 ай бұрын
Ah, the cartesian explosion. SQL is one of most underrated skills in my opinion. Great SQL skills (and DB skills in general, not just SQL) usually make your software 20x better, wheter you use ORM or not
@MilanJovanovicTech3 ай бұрын
Hey Dule :) This is an interesting one, since you'd get a similar problem even with SQL. I did exaggerate the issue by using a very large dataset, but it's still interesting.
@igorpom219 күн бұрын
Большое спасибо за видео! Очень интересно.. Поздравляю с 100 000!
@MilanJovanovicTech19 күн бұрын
Спасибо! :)
@mohammadjaber38983 ай бұрын
This is exactly why i allows have the sql profiler open My problem with the new generation of developers whos working EF without having any sql knowledge or how EF is translating I saw over a 20 include in 1 EF core call
@MilanJovanovicTech3 ай бұрын
This is why I always say to learn SQL first 😁
@pilotboba3 ай бұрын
You would also have people that don't realize the SQL query that EF writes is bad also. Cartesian explosion was an issue well before people started using ORMs. :)
@gigantedocil3 ай бұрын
Another way to get around this issue without having to use split queries if you're using Postgres is by using the built-in json aggregate functions. Instead of the database returning tons of duplicated rows due to the cartesian explosion problem you explained, it returns the exact JSON that you need. Not sure how this feature works with EF Core, but it is indeed really useful and it would be cool if you could compare both approaches!
@christian.mar.garcia3 ай бұрын
Returning json from sql is also possible in SQL server since the 2016 version. You have to store the result in a varchar(max) variable and return it.
@gigantedocil3 ай бұрын
@@christian.mar.garcia Nice, didn't know. But how do you create the structure of the JSON? Seems like you would be returning a stringified version of the result set?
@christian.mar.garcia3 ай бұрын
@@gigantedocil there are some json functions in t-sql for getting the query results in json format. You have to decide if you want to include an empty array for no data or null for some related data not present.
@MilanJovanovicTech3 ай бұрын
Hopefully we get a batching API in EF Core one day
@jordyvu9993 ай бұрын
don’t depend on EF or any orm for complex join queries with perf critical, you don’t know what happened when running, in this case call ef with your raw sql that you can control it.
@antonmartyniuk3 ай бұрын
Congratulations on 100K subscribers
@MilanJovanovicTech3 ай бұрын
Thank you so much 😀
@juanpaoc17283 ай бұрын
The cross-product in 2:54 is wrong, isn't it? It's not combining the rows correctly right? Correct me if I'm wrong
@MilanJovanovicTech3 ай бұрын
Yep, didn't update the yellow table. But seems I fixed it in the 3x3 example
@LucasRosinelli3 ай бұрын
I was going to leave a similar comment 😅 thanks @MilanJovanovicTech keep the good work
@victorcomposes3 ай бұрын
Congratulations on 100K.
@MilanJovanovicTech3 ай бұрын
Thanks!
@orterves3 ай бұрын
ORMs make this such an easy thing to get wrong by mistake, though even in the raw sql it's not necessarily obvious at a glance. It's a shame that returning complex objects from relational SQL databases never really became a 1st class feature, and we still have to resort to hacks like embedding into json or (ugh) XML, or otherwise fiddle with multi-result sets.
@MilanJovanovicTech3 ай бұрын
I don't think the ORM is to blame here
@FrancoGasperino2 ай бұрын
Problem is objects, not SQL. Data is first class.
@orterves2 ай бұрын
@@FrancoGasperino I mean support for sum types as well as product types
@DaminGamerMC3 ай бұрын
The thing is sometimes, for more complex use cases, you need joins and left jokns and many queries working together
@MilanJovanovicTech3 ай бұрын
We're not arguing against it 😁
@javidibra67863 ай бұрын
amazing content man , thanks
@MilanJovanovicTech3 ай бұрын
My pleasure!
@rohanjaykar86523 ай бұрын
could you please explian projection ? 11:00
@MilanJovanovicTech3 ай бұрын
Select(x => { take only the columns you need } )
@satriansyahw17253 ай бұрын
It’s more like in sql , u create temporary table 1 and 2 and then combine them before return to client
@MilanJovanovicTech3 ай бұрын
Won't it still have the same problem?
@xopabyteh3 ай бұрын
Amazing video, thanks
@MilanJovanovicTech3 ай бұрын
Glad you liked it!
@artemvolsh3873 ай бұрын
2:05, please add a white screen warning
@MilanJovanovicTech3 ай бұрын
I forgot 😁😁
@shubhammondal90483 ай бұрын
Congratulations for 100k.
@MilanJovanovicTech3 ай бұрын
Thanks!
@alexandrosKo3 ай бұрын
According to EF Core documentation: “Note that cartesian explosion does not occur when the two JOINs aren't at the same level” Are you sure your example applies to cartesian explosion case?
@MilanJovanovicTech3 ай бұрын
I don't know, did you watch the video?
@scottvaughan3 ай бұрын
How did you setup your benchmark project to use the AppDbContext?
@MilanJovanovicTech3 ай бұрын
Just hardcoded the connection string
@scottvaughan3 ай бұрын
@@MilanJovanovicTech any chance of the source code. Would like to try this benchmarking out for myself.
@AhmedMohammed23Ай бұрын
would as no tracking with identity help here?
@MilanJovanovicTechАй бұрын
Not really, no. Different type of issue.
@Kirides3 ай бұрын
could've mentioned the ginormous difference of data (400KB vs 18MB) on the closing "Employees" benchmark Querysplitting can drastically improve "scalability" (as in reducing shared bandwith usage) and reduce egress costs. especially for common "crud" endpoints where some entities literally join 8 tables, with 4 of them being one-to-many or many-to-many.
@MilanJovanovicTech3 ай бұрын
I was implying that by the # of records retrieved in either example
@gauravkumbhare36283 ай бұрын
Better to use linq for complex queries
@MilanJovanovicTech3 ай бұрын
Maybe, benchmark it
@PetrVejchoda3 ай бұрын
Is there any reason to have the Where method after include? I instinctively write the filter first as if in any other linq. I guess since it is translated into SQL anyway, it doesn't make much difference, but if it were some operations on IEnumerable, you would actually do Include on everything, before discarding majority of it.
@MilanJovanovicTech3 ай бұрын
I prefer having it after Include
@investycoon-app3 ай бұрын
It's a little bit off topic. Which IDE to use for doing .NET on MacOS ? Since few months, Visual Studio is deprecated. Thanks for all your videos !
@savvelev3 ай бұрын
Rider
@MilanJovanovicTech3 ай бұрын
VS Code?
@sandrorevazishvili11133 ай бұрын
Putting includes before .Where() won't make query slower?
@MilanJovanovicTech3 ай бұрын
It won't matter, since it's all translated into one SQL query
@lambo17073 ай бұрын
how did you load the related data?, did you install a package and configure something in a file?
@MilanJovanovicTech3 ай бұрын
No, just EF includes
@lambo17073 ай бұрын
@@MilanJovanovicTech interesting when we are loading related data it produces error until we configure it in program.cs
@backendsamurai3 ай бұрын
Milan, please submit your implementation of Result pattern to Github if its possible. Thanks for your rich content 👍
@MilanJovanovicTech3 ай бұрын
Хвала пуно! 😁
@Maxim.Shiryaev3 ай бұрын
As for consistency, a REPEATABLE READ transaction is to the rescue. With its own implications, of course.
@MilanJovanovicTech3 ай бұрын
Would detract from performance though
@casperhansen8263 ай бұрын
Now add a text field with Task description
@MilanJovanovicTech3 ай бұрын
What would that do?
@KREKER83313 ай бұрын
Great video , thank you.
@MilanJovanovicTech3 ай бұрын
Thank you too!
@alexkal8203 ай бұрын
So if i am correct you are basically saying that if you are using a lot of includes its bad. Then you are suggesting query splitting and then based on benchmarks query splitting is making it slower. Is this correct? If this is correct what is the punchline of the video? Because it is confusing.
@MilanJovanovicTech3 ай бұрын
I don't think you quite got this right. - The problem isn't _just_ the includes. The problem is JOINs on the same level, causing a Cartesian explosion. - Based on the benchmarks, query splitting is 9x faster in the case of a Cartesian explosion. So yes, it's needed here. - The other example, where we just have many JOINs but no Cartesian explosion, there isn't a benefit from split queries.
@TriNguyen-iz9ft3 ай бұрын
How to see the query content in EF ?
@MilanJovanovicTech3 ай бұрын
ToQuery or look at the logs
@onaspnet3 ай бұрын
There is a lot of magic (black box + documentation) to read about EF. This is why I like to use my own SQL with Dapper
@MilanJovanovicTech3 ай бұрын
You'd have the same problem in SQL
@krccmsitp28843 ай бұрын
The EF Core docs are very comprehensive and detailed.
@onaspnet3 ай бұрын
@MilanJovanovicTech however, inefficient joins are easier to observe and fix.
@onaspnet3 ай бұрын
@krccmsitp2884 true and long
@kristiadhy3 ай бұрын
Do you write the SQL statement as part of the code in Dapper or do you use StoreProc? Because in my experience I have made a lot of mistakes caused by typing the wrong SQL statement. That's what I don't like about Dapper. I always prefer using strong type.
@Andrii.S163 ай бұрын
Could you suggest a tool for working with SQL Server databases? I find Azure Data Studio a bit lacking.
@rafapioli753 ай бұрын
DBeaver is a great tool to use with SQL Server!
@xtazyxxx34873 ай бұрын
SSMS
@MilanJovanovicTech3 ай бұрын
DBeaver is great
@mridulpaul13783 ай бұрын
May I get source code of it?
@MilanJovanovicTech3 ай бұрын
www.patreon.com/posts/source-code-are-111190292
@zahidcakici79683 ай бұрын
Bro why you just didn't filter employeeId (Where(e => e.Id == id)) before the include ?
@MilanJovanovicTech3 ай бұрын
What difference would it make? 😅 This is LINQ -> SQL
@zahidcakici79683 ай бұрын
@@MilanJovanovicTech So you are saying that EfCore optimises query and filter the where query before join or it just doesn’t matter if we filter before join or not?
@omarjamil94493 ай бұрын
How can I appear database icon next to entity class? 😅😅
@MilanJovanovicTech3 ай бұрын
ReSharper
@mzuvin3 ай бұрын
I know that pagination does not work in split query.
@MilanJovanovicTech3 ай бұрын
Probably (but that won't suffer from this issue as much since we're limiting the # of rows we return)
@enricoroselino75573 ай бұрын
wait i might done this 😂 ill check asap
@MilanJovanovicTech3 ай бұрын
And...? 😁
@mzuvin3 ай бұрын
splitting the query is not a magic feature, it is proof that ef core is slow.
@MilanJovanovicTech3 ай бұрын
Slow is relative
@RayZde2 ай бұрын
If you want performance, its simple. Dont use EF.
@MilanJovanovicTech2 ай бұрын
Some people can't be helped
@nonadequateuser74013 ай бұрын
Am I only one guy who hates EF and don't understand why people still using it?
@MilanJovanovicTech3 ай бұрын
Among the few
@ishitvyas3 ай бұрын
Yes you are
@filipnikolic22803 ай бұрын
Probably
@algorithm-artisan3 ай бұрын
Yes
@kristiadhy3 ай бұрын
So what is your alternative? I know there is another option like Dapper. But I don't like writing the SQL statement as part of the code because it's prone to errors or typos.
@taiphanvan24033 ай бұрын
Is AsSplitQuery effective when I use the navigation properties in the Select method rather than Include? In the Select method, I only fetch some necessary properties of navigation property rather than fetch all them. Example: var employees = await context .Employees .Select(e => new EmployeeDto() { Salary = e.SalaryPayment... }).ToListAsync();
@xtazyxxx34873 ай бұрын
Try linqpad to see the sql generated by the linq query. Normally include create joins whereas projection creates subqueries
@MilanJovanovicTech3 ай бұрын
Well it's hard to tell from your small example, but you can easily test if split queries work better