我尝试禁用这两种方式的延迟加载:
1)
public SqlDbContext(DbContextOptions<SqlDbContext> options) : base(options)
{
this.ChangeTracker.LazyLoadingEnabled = false;
}
2)
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<SqlDbContext>(options => {
options.UseSqlServer(Configuration.GetConnectionString("SqlDbContext"));
options.UseLazyLoadingProxies(false);
});
而且我在导航中不使用关键字“虚拟”。
不幸的是,延迟加载仍在工作。我想禁用它,只强制使用紧急加载,所以当我忘记使用Include()时抛出错误。
但是使用thouse两种方法,查询仍然会返回结果。