Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active Jul 28, 2021
Embed
What would you like to do?
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