Комментарии:
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
Ответить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.
ОтветитьYou are a star mate!! Thanks for your tutorials!!
Ответить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
ОтветитьU are awesome man
ОтветитьLove from Pakistan ! love that extension part.
ОтветитьThank you and again greetings from Bulgaria.
As per your instruction and per my liking I smashed the like button.
another brilliant tutorial !!!
ОтветитьYou're amazing
ОтветитьThis is great. I just added this WhereIf extension method to a new API I started working on. Thanks!
Ответить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. ✌️🥸
Ответитьproject git link please
Ответить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)
ОтветитьHello Milan, great video again!!
Any good advice or video for efcore bulk insert?
Great, Thanks.
Ответить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.
ОтветитьHow did you managed to print actual query in the console?
Ответить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()
Ответить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.
Ответить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)
I always compose my queries this way, but adding an extension method is a great tip.
ОтветитьGood one Milan, thanks!
Ответить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 :)
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
ОтветитьJust a random suport comment .... great staff keep em coming ... ajde :)
ОтветитьAmazing channel
ОтветитьGreat content !!!
One question, where would you implement this extension method in a clean architecture? Is it in infrastructure layer?
Hi, there is a way to remove the check empty in the generate sql query?
Ответить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.
Very useful, adding it on my project 😛
Ответить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.
Ответить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.
Great approach. such simple tweak but adds so much clarity to code
Ответитьi used it in various queries, thanks for the video 👏
ОтветитьDoes OData take care of empty filter internally?
ОтветитьNice
Ответить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
Thanks Milan😊
ОтветитьGreat tip, I usually put if statements in my repo, but this makes me realize I'm under utilizing extensions yet again.
ОтветитьVery nice bit of technique.
ОтветитьThanks Milan, you always amazing me 👍.
ОтветитьI find it very helpful
ОтветитьInteresting 🤔
Ответитьvery nice😄
ОтветитьI always learn new things with your videos 😄
Always a new perspective on things that are familiar to me.
It's great! 😅