Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active July 28, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/45694236856f38921d99a200314a0b30 to your computer and use it in GitHub Desktop.
Save explorer14/45694236856f38921d99a200314a0b30 to your computer and use it in GitHub Desktop.
static async Task Main(string[] args)
{
using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
await Save(product);
// we might update more entities
scope.Complete();
}
}
public static async Task Save(Product product)
{
using (var connection = new MySqlConnection(“...”))
{
await connection.OpenAsync();
// select count(1) from Products where Id = @id
if (await Exists(product, connection))
// update Products set ... where Id = @id
await Update(product, connection);
else
// insert into Products values(...)
await Insert(product, connection);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment