My LazyLoadingProxies not work after I config my DbContext using LazyLoadingProxies here:
services.AddDbContextPool<DbContext, ApplicationDbContext>((provider, builder) =>
{
var configuration = provider.GetRequiredService<IConfiguration>();
var options = provider.GetRequiredService<IOptions<SqlServerRetryOptions>>();
builder
.EnableDetailedErrors(true)
.EnableSensitiveDataLogging(true)
.UseLazyLoadingProxies(true) // => If UseLazyLoadingProxies, all of the navigation fields should be VIRTUAL
.UseSqlServer(
connectionString: configuration.GetConnectionString("ConnectionStrings"),
sqlServerOptionsAction: optionsBuilder
=> optionsBuilder.ExecutionStrategy(
dependencies => new SqlServerRetryingExecutionStrategy(
dependencies: dependencies,
maxRetryCount: options.Value.MaxRetryCount,
maxRetryDelay: options.Value.MaxRetryDelay,
errorNumbersToAdd: options.Value.ErrorNumbersToAdd))
.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.GetName().Name));
});
Here is RoleEntity:
public class Role : DomainEntity<int>
{
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<User> Users { get; set; }
}
I dont know why Users of Role is also include even though I dont use Include in the code
public List<Role> FindAll()
=> context.Role.ToList();