public static async Task MainAsync(IQuoteRepository repo, ITransactionSessionFactory transactionSessionFactory) { var tasks = new List <Task>(); for (int i = 0; i < 1000; i++) { tasks.Add(Insert(repo, transactionSessionFactory, $"Product {i}", $"Customer {i}")); } await Task.WhenAll(tasks); }
public static async Task Insert(IQuoteRepository repo, ITransactionSessionFactory transactionSessionFactory, string productName, string customerName) { using (var trans = transactionSessionFactory.Create()) { try { var quoteId = await repo.SaveAsync(new Quote(productName)); await repo.SaveAsync(new QuoteCustomer(quoteId, customerName)); trans.Commit(); } catch (Exception e) { trans.Rollback(); throw; } } }