'Perform multiple ASP.NET Core Identity UserManager calls atomically

In my system, username and email are the same. I want to make multiple UserManager calls atomically, e.g.

userManager.ChangeEmailAsync(...);
userManager.SetUserNameAsync(...);

On the repo it was explained that this cannot be done with UserManager, as it doesn't directly support transactions.

However UserManager relies on a DbContext. Is there a way to use a context transaction to perform an atomic operation as above?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source