Last active
July 28, 2021 21:19
-
-
Save explorer14/45694236856f38921d99a200314a0b30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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