How can I enable the QueryFilters again in EntityFramework Core after calling IgnoreQueryFilters?

c# entity-framework entity-framework-core

Accepted Answer

You may be able to utilize a Non-Tracking Query for this kind of progress.

This is linked to her. https://docs.microsoft.com/en-us/ef/core/querying/tracking

A straightforward usage—you may need to add a few items. This code wasn't debugged by me.

GetAllWithoutFilter

Context.Set<TEntity>().AsNoTracking().IgnoreQueryFilters();

GetAllAsNoTracking

Context.Set<TEntity>();

public virtual IQueryable<TEntity> GetAllWithoutFilter(string[] include)
{
    IQueryable<TEntity> query = Context.Set<TEntity>().AsNoTracking().IgnoreQueryFilters();

    if (include != null)
    {
        query = include.Aggregate(query, (current, includePath) => current.Include(includePath));
    }

    return query;
}


public virtual IQueryable<TEntity> GetAll(string[] include)
{
    IQueryable<TEntity> query =  Context.Set<TEntity>();

    if (include != null)
    {
        query = include.Aggregate(query, (current, includePath) => current.Include(includePath));
    }

    return query;
}
3
2/16/2018 7:46:17 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow