File tree Expand file tree Collapse file tree 4 files changed +27
-2
lines changed
src/shared/Z.EF.Plus.QueryFuture.Shared Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ public abstract class BaseQueryFuture
7070 /// <value>The query connection.</value>
7171 internal IRelationalConnection QueryConnection { get ; set ; }
7272
73+ internal Action RestoreConnection { get ; set ; }
74+
7375 public virtual void ExecuteInMemory ( )
7476 {
7577
@@ -180,8 +182,11 @@ public virtual IRelationalCommand CreateExecutorAndGetCommand(out RelationalQuer
180182
181183 var innerConnection = new CreateEntityConnection ( QueryConnection . DbConnection , null ) ;
182184 var innerConnectionField = typeof ( RelationalConnection ) . GetField ( "_connection" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
185+ var initalConnection = innerConnectionField . GetValue ( QueryConnection ) ;
183186
184187 innerConnectionField . SetValue ( QueryConnection , new Microsoft . EntityFrameworkCore . Internal . LazyRef < DbConnection > ( ( ) => innerConnection ) ) ;
188+
189+ RestoreConnection = ( ) => innerConnectionField . SetValue ( QueryConnection , initalConnection ) ;
185190 }
186191
187192
Original file line number Diff line number Diff line change @@ -117,6 +117,8 @@ public void ExecuteQueries()
117117 }
118118
119119 var connection = Context . Database . GetDbConnection ( ) ;
120+
121+ var firstQuery = Queries [ 0 ] ;
120122#endif
121123 var command = CreateCommandCombined ( ) ;
122124
@@ -173,6 +175,13 @@ public void ExecuteQueries()
173175 connection . Close ( ) ;
174176 }
175177 }
178+
179+ #if EFCORE
180+ if ( firstQuery . RestoreConnection != null )
181+ {
182+ firstQuery . RestoreConnection ( ) ;
183+ }
184+ #endif
176185 }
177186
178187#if NET45
@@ -217,6 +226,8 @@ public async Task ExecuteQueriesAsync()
217226 }
218227
219228 var connection = Context . Database . GetDbConnection ( ) ;
229+
230+ var firstQuery = Queries [ 0 ] ;
220231#endif
221232 var command = CreateCommandCombined ( ) ;
222233
@@ -273,6 +284,13 @@ public async Task ExecuteQueriesAsync()
273284 connection . Close ( ) ;
274285 }
275286 }
287+
288+ #if EFCORE
289+ if ( firstQuery . RestoreConnection != null )
290+ {
291+ firstQuery . RestoreConnection ( ) ;
292+ }
293+ #endif
276294 }
277295#endif
278296
Original file line number Diff line number Diff line change @@ -167,8 +167,10 @@ public override void GetResultDirectly()
167167
168168 internal void GetResultDirectly ( IQueryable < T > query )
169169 {
170- using ( var enumerator = query . GetEnumerator ( ) )
170+ using ( var enumerator = query . GetEnumerator ( ) )
171+ {
171172 SetResult ( enumerator ) ;
173+ }
172174 }
173175 }
174176}
Original file line number Diff line number Diff line change 1- v1.7.4
1+ v1.7.5
You can’t perform that action at this time.
0 commit comments