just a note... in practice, this approach won't work for large numbers of entities.  A couple of things can go wrong - the number and/or size of the entities may be too large and cause an out-of-memory condition, or the number of operations can take longer than the allowed request duration.  This is a good starting implementation; in the future it would be good to implement this in a background task that breaks the work into chunks, monitors the time spent, and queues follow up tasks as necessary in a chain until all the chunks have been processed.