-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Is it possible to use IgnoreQueryFilters in an explicit load? #21349
Comments
@maumar @smitpatel Do we have an overall issue tracking improvements to the usability of query filters? |
Though you might like to know that I have found a way to apply a I consider this issue closed, but you might like to provide a version of private void LoadNavigationCollection(object principalInstance, INavigation navigation)
{
if (_set)
//For setting we can simple load it, as we don't want to set anything that is already set
_context.Entry(principalInstance).Collection(navigation.PropertyInfo.Name).Load();
else
{
//for undoing a soft delete we need to load the collection with a IgnoreQueryFilters method
var navValueType = navigation.PropertyInfo.PropertyType;
var innerType = navValueType.GetGenericArguments().Single();
var genericHelperType =
typeof(GenericCollectionLoader<>).MakeGenericType(innerType);
Activator.CreateInstance(genericHelperType, _context, principalInstance, navigation.PropertyInfo);
}
}
private class GenericCollectionLoader<TEntity> where TEntity : class
{
public GenericCollectionLoader(DbContext context, object principalInstance, PropertyInfo propertyInfo)
{
var query = context.Entry(principalInstance).Collection(propertyInfo.Name).Query();
var collection = query.Provider.CreateQuery<TEntity>(query.Expression).IgnoreQueryFilters().ToList();
propertyInfo.SetValue(principalInstance, collection);
}
} |
@JonPSmith We're tracking making this easier in #17347. Also, I have created an overall issue for improving the query filter experience. |
Your link is broken - see #21459 for link to Improve usability of global query filters issue. |
Updated broken link. |
This isn't a feature request, but a question. Wasn't sure where I should post questions.
I'm looking at creating a soft delete method that mimics the cascade delete. For instance if I had relationships
GrandFather -> Father -> Son
I soft deleteGrandFather
it would also soft delete theFather
andSon
too. This could be useful in some situations.To do this I use explicit loading to load any relationships, e.g. for collections
_context.Entry(principalInstance).Collection(navigation.PropertyInfo.Name).Load();
The soft delete works, but the un-soft delete doesn't because I need to load the relationships with
IgnoreQueryFilters
method in it, and I can't find a way to do that.Can you suggest a way around this? Building a real query is doable, but quite hard to get right for all situations. The other option is to cast the
_context.Entry(principalInstance).Collection(navigation.PropertyInfo.Name).Query()
to the right form to apply theIgnoreQueryFilters()
method.Any wisdom greatly received.
PS. If you are interested the current version of the CascadeSoftDelService can be found here.
The text was updated successfully, but these errors were encountered: