我使用 Ef Core 2.1,启用了软删除查询过滤器。在某些情况下,我想从实体中检索已软删除的导航属性,但无法检索数据(导航属性为空,因为它已被软删除)。我使用了这个 doc(编写于2017年)作为参考,其中指出:
“过滤器不能包含对导航属性的引用。”
我希望知道是否有任何方法可以启用这种行为。
作为一则旁注,我想说明的是我在 StartUp.cs 中使用了懒加载代理。
“过滤器不能包含对导航属性的引用。”
我希望知道是否有任何方法可以启用这种行为。
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;
作为一则旁注,我想说明的是我在 StartUp.cs 中使用了懒加载代理。
services.AddDbContext<ApplicationDbContext>(options =>
options.UseLazyLoadingProxies().UseSqlServer(connectionString));
我的模型比这里给出的示例更复杂,因此不使用'Include()'和'ThenInclude()'. 使用include会使代码变得更加复杂和难以维护。
.IgnoreQueryFilters()
吗? - Fabio