@@ -10,6 +10,7 @@ public abstract class MyDbContextBase : DbContext
1010 private readonly string _databaseName ;
1111 private readonly bool _useQueryableValues ;
1212 private readonly bool _useSelectTopOptimization ;
13+ private readonly bool _useUseDeferredEnumeration ;
1314
1415#if ! EFCORE3
1516 public event Action < string > ? LogEntryEmitted ;
@@ -20,12 +21,14 @@ public abstract class MyDbContextBase : DbContext
2021 public MyDbContextBase (
2122 string databaseName ,
2223 bool useQueryableValues = true ,
23- bool useSelectTopOptimization = true
24+ bool useSelectTopOptimization = true ,
25+ bool useUseDeferredEnumeration = true
2426 )
2527 {
2628 _databaseName = databaseName ;
2729 _useQueryableValues = useQueryableValues ;
2830 _useSelectTopOptimization = useSelectTopOptimization ;
31+ _useUseDeferredEnumeration = useUseDeferredEnumeration ;
2932 }
3033
3134 protected override void OnConfiguring ( DbContextOptionsBuilder optionsBuilder )
@@ -34,7 +37,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
3437
3538#if ! EFCORE3
3639 optionsBuilder . LogTo (
37- logEntry => {
40+ logEntry =>
41+ {
3842 LogEntryEmitted ? . Invoke ( logEntry ) ;
3943 } ,
4044 Microsoft . Extensions . Logging . LogLevel . Information ) ;
@@ -46,7 +50,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
4650 {
4751 if ( _useQueryableValues )
4852 {
49- var applyOptions = ! _useSelectTopOptimization ;
53+ var applyOptions = ! _useSelectTopOptimization || ! _useUseDeferredEnumeration ;
5054
5155 if ( applyOptions )
5256 {
@@ -56,6 +60,13 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
5660 {
5761 options . UseSelectTopOptimization ( false ) ;
5862 }
63+
64+ #if ! EFCORE3
65+ if ( ! _useUseDeferredEnumeration )
66+ {
67+ options . UseDeferredEnumeration ( false ) ;
68+ }
69+ #endif
5970 } ) ;
6071 }
6172 else
0 commit comments