Last active
January 10, 2020 08:57
-
-
Save Bert-Proesmans/60bff84c562562c94c389660e8cdfe9b to your computer and use it in GitHub Desktop.
EntityFramework and async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Test { | |
static async Task ExecuteWithChangedEntitiesInnerAwait<T>(Func<IEnumerable<T, Task>> handling) { | |
using(var ctxt = _ctxtFactory()) { | |
var entities = ctxt.Set<T>(); | |
await handling(entities); | |
} | |
} | |
static Task ExecuteWithChangedEntitiesNoAwait<T>(Func<IEnumerable<T, Task>> handling) { | |
using(var ctxt = _ctxtFactory()) { | |
var entities = ctxt.Set<T>(); | |
return handling(entities); | |
} | |
} | |
static Task Handler<T>(IEnumerable<T> entities) { | |
IEnumerable<Task> updateTasks = entities.Batch(100).SelectMany(x => _handlers.HandleBatch(x)); | |
return Task.WhenAll(updateTasks); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment