Disable softDelete Query filters for navigation properties

.net-core c# entity-framework-core soft-delete

Question

I use Ef Core 2.1, in which I enabled a soft-delete query filter.

In some cases, I want to retrieve from an entity, a soft-deleted navigation property, but I could not retrieve the data (The navigation property is null because it was soft deleted).

I used this doc (which was written in 2017) as a reference, and it is stated that

Filters cannot contain references to navigation properties.

I wish to know If there is any way to enable such behaviour.

public class Form {

    public int Id { get; set; }

    public virtual Sprint Sprint {get; set;}
}

public class Sprint: ISoftDeleteable {

    public int Id { get; set; }

    public string Name {get; set;}
}

// Indicates that every model that implements this interface should use soft delete.
public interface ISoftDeleteable
{ 

}

 // Both statements have returned null.
 Sprint sprint = applicationDbContext.Forms.FirstOrDefault(f => f.Id == 1).Sprint;
 Sprint sprint = applicationDbContext.Forms.IgnoreQueryFilters().FirstOrDefault(f => f.Id == 1).Sprint;

As a side note, I wish to state that I use a lazy loading proxy in StartUp.cs

services.AddDbContext<ApplicationDbContext>(options => 
    options.UseLazyLoadingProxies().UseSqlServer(connectionString));

Instead of using using 'Include()' and 'ThenInclude()', Because my model, is more complex than the exmplle given here. Using include will make the code more complicated and unmaintainable.

1
0
7/8/2019 8:11:53 AM

Popular Answer

try this

var data = DbContext.Set<Table>().IgnoreQueryFilters().ToList();

or

var data = DbContext.TableName.IgnoreQueryFilters().ToList();
3
7/8/2019 6:55:21 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