Skip to content

Commit 008661a

Browse files
authored
Merge pull request snickler#19 from DillonAd/master
Allow users to manage connections outside of library
2 parents 116e98d + f074c87 commit 008661a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

EFCoreFluent/src/EFCoreFluent/EFExtensions.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private IList<T> MapToList<T>(DbDataReader dr)
194194
/// <typeparam name="T"></typeparam>
195195
/// <param name="command"></param>
196196
/// <returns></returns>
197-
public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults> handleResults, System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default)
197+
public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults> handleResults, System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default, bool manageConnection = true)
198198
{
199199
if (handleResults == null)
200200
{
@@ -203,7 +203,7 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
203203

204204
using (command)
205205
{
206-
if (command.Connection.State == System.Data.ConnectionState.Closed)
206+
if (manageConnection && command.Connection.State == System.Data.ConnectionState.Closed)
207207
command.Connection.Open();
208208
try
209209
{
@@ -216,7 +216,10 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
216216
}
217217
finally
218218
{
219-
command.Connection.Close();
219+
if(manageConnection)
220+
{
221+
command.Connection.Close();
222+
}
220223
}
221224
}
222225
}
@@ -227,7 +230,7 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
227230
/// <typeparam name="T"></typeparam>
228231
/// <param name="command"></param>
229232
/// <returns></returns>
230-
public async static Task ExecuteStoredProcAsync(this DbCommand command, Action<SprocResults> handleResults, System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default, CancellationToken ct = default(CancellationToken))
233+
public async static Task ExecuteStoredProcAsync(this DbCommand command, Action<SprocResults> handleResults, System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default, CancellationToken ct = default(CancellationToken), bool manageConnection = true)
231234
{
232235
if (handleResults == null)
233236
{
@@ -236,7 +239,7 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
236239

237240
using (command)
238241
{
239-
if (command.Connection.State == System.Data.ConnectionState.Closed)
242+
if (manageConnection && command.Connection.State == System.Data.ConnectionState.Closed)
240243
await command.Connection.OpenAsync(ct).ConfigureAwait(false);
241244
try
242245
{
@@ -248,7 +251,10 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
248251
}
249252
finally
250253
{
251-
command.Connection.Close();
254+
if (manageConnection)
255+
{
256+
command.Connection.Close();
257+
}
252258
}
253259
}
254260
}

0 commit comments

Comments
 (0)