Skip to content

Instantly share code, notes, and snippets.

@Bert-Proesmans
Last active January 10, 2020 08:57
Show Gist options
  • Save Bert-Proesmans/60bff84c562562c94c389660e8cdfe9b to your computer and use it in GitHub Desktop.
Save Bert-Proesmans/60bff84c562562c94c389660e8cdfe9b to your computer and use it in GitHub Desktop.
EntityFramework and async
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