I want to disable lazy loading in EF Core. Right now I have an infinite loop of loading relations. By running the below code, I get an Employee with all relations to the Employee, even if lazy loading is disabled.
public EmployeeProcess GetByEmployeeNr(int employeeNr)
{
if (_db.EmployeeProcess.Any(ep => ep.Employee.Id == employeeNr))
return _db.EmployeeProcess.First(ep => ep.Employee.Id == employeeNr);
return null;
}
To turn of relations I have tried to write the following in the constructor of the context:
this.ChangeTracker.LazyLoadingEnabled = false;
I have also tried to do it in the repository by using:
db.ChangeTracker.LazyLoadingEnabled = false;
On other posts I have read that Context.Configuration.LazyLoadingEnabled = false, is the way to go, but I have no Configuration in my Context.
The empty constructor looks like this:
public SalRegContext(DbContextOptions<SalRegContext> options) : base(options) { }
Does someone know how to get the configuration, or another solution to prevent the infinite loop of relations?
this.ChangeTracker.LazyLoadingEnabled = false; Does not work..
Context.Configuration.LazyLoadingEnabled = false; is not possible, as there is no configuration.