One LINQ Extension Method You NEED To Know For Cleaner EF Core Queries

One LINQ Extension Method You NEED To Know For Cleaner EF Core Queries

Milan Jovanović

1 год назад

20,506 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Alupl
@Alupl - 18.12.2023 20:55

I'm using this Extension method since .NET Framework 4 :D Today in .NET Core 8.0 I'm surprised there still isn't such build in method (or I don't know of it). Funny thing is that very few programmers know this but as you showed in your video, It's so much simpler and effective. I don't get it why this isn't a standard ... Anyway thanks for your vid - I didn't remember the syntax and came here :P

Ответить
@Mohamad-jz1qz
@Mohamad-jz1qz - 13.12.2023 08:38

Hi, I want to know that if we have a large amount of data, this approach won't be failed? because firstly your are going to select all and then filter outside of sql. Thanks in advanced.

Ответить
@niangel2704
@niangel2704 - 02.12.2023 23:18

You are a star mate!! Thanks for your tutorials!!

Ответить
@WahidRezgui
@WahidRezgui - 31.10.2023 11:05

Hello first of all thanks for the video . Ihave one question do you have any idea how to make the operator like =,>,< generic and selected by user like the sample you provided Age =10 or age>10

Ответить
@ahmedh2482
@ahmedh2482 - 25.09.2023 01:47

U are awesome man

Ответить
@hassanOnYoutube
@hassanOnYoutube - 12.09.2023 21:16

Love from Pakistan ! love that extension part.

Ответить
@mocococo2877
@mocococo2877 - 08.08.2023 22:34

Thank you and again greetings from Bulgaria.

As per your instruction and per my liking I smashed the like button.

Ответить
@techpc5453
@techpc5453 - 03.07.2023 14:59

Ответить
@arunbm123
@arunbm123 - 25.06.2023 07:42

another brilliant tutorial !!!

Ответить
@waleedbensumaidea3947
@waleedbensumaidea3947 - 01.05.2023 22:30

You're amazing

Ответить
@joehernandez3231
@joehernandez3231 - 21.04.2023 23:46

This is great. I just added this WhereIf extension method to a new API I started working on. Thanks!

Ответить
@Knusperfunk
@Knusperfunk - 22.03.2023 12:01

Love it! Your method is identical to the one I wrote a couple of months ago (except that I used a ternary conditional operator). It feels like an implicit compliment. ✌️🥸

Ответить
@anime-dx4tz
@anime-dx4tz - 06.03.2023 18:32

project git link please

Ответить
@Davsan1
@Davsan1 - 26.02.2023 14:59

Hmm, usually when I include an optional filter parameter use a nullable string argument, then I'm suspecting Visual Studio would give me the ole' green squiggly lines in the Where() because it wouldn't be able to figure out that we actually are checking for null in the if(condition)

Ответить
@tsatsosgregorian9410
@tsatsosgregorian9410 - 24.02.2023 11:06

Hello Milan, great video again!!
Any good advice or video for efcore bulk insert?

Ответить
@rankarat
@rankarat - 20.02.2023 23:13

Great, Thanks.

Ответить
@OddbjornBakke
@OddbjornBakke - 19.02.2023 19:49

Interesting approach. As every permutation of conditions in code would generate new SQL, and therefor new query plans... that again could impact performance. It would be interesting to hear a DBAs view on this. Might be a good thing, and might be a bad thing. I am actually not sure.

Ответить
@VishnuKumar-fq1zo
@VishnuKumar-fq1zo - 18.02.2023 17:16

How did you managed to print actual query in the console?

Ответить
@MortvmMM
@MortvmMM - 18.02.2023 14:40

Nice extension method :) A nice fluent alternative to building your queries. The basic way of doing it is marking your query AsQueryable and adding to it like if (condition) query = query.Where()

Ответить
@addkim7889
@addkim7889 - 18.02.2023 12:17

Really a clever way to apply condition, making the input as a Func<bool> instead of bool would make it more adaptable, plus the Expression Api is used for Linq, and EfCore, and other ORM, used that to compose the actual query.

Ответить
@winchester2581
@winchester2581 - 18.02.2023 02:12

Simple, but awesome and useful video, used this approach on one of the previous projects :)
Also when I worked there, I've got a hint of not using Where statement in the loop, 'cuz it's gonna generate a lot of queries which is not really convenient in terms of performance, so we used LinqKit for that (to combine specific filters to apply to query)
So I think that such videos really helps developers to write LINQ expressions wisely, my kudos)

Ответить
@pilotboba
@pilotboba - 18.02.2023 00:13

I always compose my queries this way, but adding an extension method is a great tip.

Ответить
@majormartintibor
@majormartintibor - 17.02.2023 23:33

Good one Milan, thanks!

Ответить
@haythambiadse5137
@haythambiadse5137 - 17.02.2023 23:12

can you think of situations it could help to improve performance?

also ,can you please do a video for queries that runs inside a loop ... ? i bet you have great tips over this :)

Ответить
@mylesdavies9476
@mylesdavies9476 - 17.02.2023 22:20

Hi Milan, really enjoyed your tech talk on modular monolith. It would be great if you could do a video outlining the basic building blocks, i.e. your preferred approach for bringing the modules together and explaining some of the core concepts

Ответить
@fitstrong167
@fitstrong167 - 17.02.2023 21:05

Just a random suport comment .... great staff keep em coming ... ajde :)

Ответить
@user-pr4yj1wr1s
@user-pr4yj1wr1s - 17.02.2023 20:14

Amazing channel

Ответить
@andresjimenez3140
@andresjimenez3140 - 17.02.2023 19:23

Great content !!!
One question, where would you implement this extension method in a clean architecture? Is it in infrastructure layer?

Ответить
@nico11323
@nico11323 - 17.02.2023 19:20

Hi, there is a way to remove the check empty in the generate sql query?

Ответить
@mptechie
@mptechie - 17.02.2023 18:55

Generally, this is a good extension, but in real applications, your querying conditions will most likely be more complex and include much more business-logic.
Whether this is due to the architect's failure to abstract it away from the data layer or due to technical debt is irrelevant, it's something that happens.
Don't ever implement business logic within a generic method, instead, you can build the query before you materialize the results with .ToList() or similar using the IQueryable.

Ответить
@sanampakuwal
@sanampakuwal - 17.02.2023 18:11

Very useful, adding it on my project 😛

Ответить
@JavierAcrich
@JavierAcrich - 17.02.2023 17:56

If I call the extension method WhereIf, I would have the predicate as a first parameter and the condition second. Otherwise I would call it 'IfWhere'. So it has concordance with the parameter order.

Ответить
@volodymyrliashenko1024
@volodymyrliashenko1024 - 17.02.2023 17:25

I'm a big fun of this extension method and I have different versions of it
Wondering, how devs who like Dapper implement such logic.

Ответить
@NavedDeshmukh
@NavedDeshmukh - 17.02.2023 17:14

Great approach. such simple tweak but adds so much clarity to code

Ответить
@mohamed-hassan-
@mohamed-hassan- - 17.02.2023 17:12

i used it in various queries, thanks for the video 👏

Ответить
@meirkr
@meirkr - 17.02.2023 17:08

Does OData take care of empty filter internally?

Ответить
@delphiguy23
@delphiguy23 - 17.02.2023 16:46

Nice

Ответить
@Tamer_Ali
@Tamer_Ali - 17.02.2023 16:45

Is there a better approach (generic) to filter data from 2 lists to save to database?
e.g:
list1 is the existing users from database
list2 is the users that the admin want to add, update or delete after comparing with the existing users in the database

Ответить
@user-og2kd2vn4g
@user-og2kd2vn4g - 17.02.2023 16:39

Thanks Milan😊

Ответить
@josephmilazzo8713
@josephmilazzo8713 - 17.02.2023 16:32

Great tip, I usually put if statements in my repo, but this makes me realize I'm under utilizing extensions yet again.

Ответить
@codingbloke
@codingbloke - 17.02.2023 16:29

Very nice bit of technique.

Ответить
@Tamer_Ali
@Tamer_Ali - 17.02.2023 16:26

Thanks Milan, you always amazing me 👍.

Ответить
@krunalsisodiya
@krunalsisodiya - 17.02.2023 16:26

I find it very helpful

Ответить
@KunalMukherjee3701
@KunalMukherjee3701 - 17.02.2023 16:02

Interesting 🤔

Ответить
@TheSead750
@TheSead750 - 17.02.2023 15:31

very nice😄

Ответить
@drozdgabriel
@drozdgabriel - 17.02.2023 15:18

I always learn new things with your videos 😄
Always a new perspective on things that are familiar to me.
It's great! 😅

Ответить