How To Apply Global Filters With EF Core Query Filters

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

In this video, we'll be talking about the EF Core query filters feature and how we can use it to define global query filters. Query filters are a lesser-known EF Core feature, but they certainly don't deserve it. We'll see how we can use EF query filters, to satisfy a new requirement for the existing repository implementation. And I'll also discuss potential issues that you can run into when using EF query filters.

Join my weekly .NET newsletter:

How to Use Query Filters in EF Core

Read my Blog here:

Subscribe for more:

Chapters
0:00 How to implement Query Filters
4:27 How Query Filters work
6:15 How to ignore Query Filters
8:20 One thing to be careful about
Рекомендации по теме
Комментарии
Автор

Nice video explanation sir. Thank you! Based on my experience, I don't usually use query filter as they are hard to troubleshoot for junior dev within the team. I do IQueryable extension like

static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
{
if (condition) return query.Where(predicate)
else return query
}

maynardpaye
Автор

Thanks for great video. I am using query filter on project, and also we have problem in legasy parts with with QueryFilter that you show in this video, which no one noticed for a 3 year 🤣
So I have just fixed it, and I received compliment from all team

atler
Автор

I wrote a bunch of needless code to create a user manager derived class to add a global filter. I scrapped it and used your method which is much cleaner.

spaces
Автор

Thanks for sharing!
I was about to ask how to ignore the global filter and answered.

volodymyrliashenko
Автор

Thanks Milan your videos helps me a lot.

wiliampaulino
Автор

EF query filter is a great feature. I did 2 multitenant(Based on CompanyId) applications using it and works well.

stunna
Автор

Zgodna stvar. Volim ove forice koje na elegantan nacin smanje kod i potencijalne glavobolje kad nesto ne radi.
Subbed :)

Zicru
Автор

Nice topic, love the videos you do on EF Core, as you mentioned EF Core is a feature-rich library so there are lot's to explore, thank you for the efforts you put in these videos.

cyrildouglas
Автор

Nice video, Milan!
I was just looking for a feature like this in EF. I initially thought about adding a condition in my base specification, but wanted an approach like Eloquent Scopes from Laravel.
Thanks for the content.

elitonluiz
Автор

Right to the point the point Milan, awesome as usual

ibrahimhebish
Автор

Very nice feature :) i have never heard about it. I am going to apply it because we are using soft delete in each project :)

patrykklimas
Автор

6:42 What?? You're holding out on me?? I want the answer now!! Lol, already subscribed hoss, thanks for the great and informative vids :)

mtranchi
Автор

Very nice. I did not think to use this in support of not querying IsActive or IsDeleted, etc.. I would like another video on the topic of Filters - Dynamic Filter Pattern??

sampleuser
Автор

This is a nice explanation of global filters, but as shipped the global filters feature is somewhat limited:

In only applies to the base class in an object hierarchy, so for example if I have a base class of shape and superclasses of square and circle with a discriminator column I can't use the filter when I query square or circle - even if I have DBSets for each.

It doesn't support non boolean filters. I'm accessing a table which is partitioned by user id and just fixed a bug where I'd forgotten to include the .Where(c => c.UserID == currentUserId) clause. It would be great to be able to include that as a global filter.

It's a good start!

davearkley
Автор

Hey Milan, nice video! As you mentioned Quantum computing, do you consider making a video about this topic in the future ?

tonystoynev
Автор

Very nice, I’m curious about extension you’re visual studio when is debugging, you can say what’s name ?

ItsSalesGabriel
Автор

Nice video.
Recently, I've been dealing with an alike scenario where I have to read from DB where the entries' deletion is soft. However, we were using the database first approach, So, is this valid when we are generating models from an existing DB ?

MrAymenmatador
Автор

Hi Milan,

Is there a way to apply a query filter just once to a group of entities, say, to all domain entities that implement ISoftDeletableEntity interface?

sashamarfut
Автор

Nice tool. Only soft remove. Other options don't come to mind.

elmanaw
Автор

Hey, great video, I have a question, if you have Default query filters where you ignore IsDeleted != null, and you want to use it but want to show foreign elements like user who created it. Lets say user is deleted, in that case search Table that you wanted will always return null, so my question is can you limit DefaultQuery to depth, or you need to go with different aproach?

rade