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.
try this
var data = DbContext.Set<Table>().IgnoreQueryFilters().ToList();
or
var data = DbContext.TableName.IgnoreQueryFilters().ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With