-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (31 loc) · 1.05 KB
/
Program.cs
File metadata and controls
40 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.Concurrent;
using System.Transactions;
using Microsoft.EntityFrameworkCore;
namespace OracleApp;
internal class Program
{
static async Task Main(string[] args)
{
Console.WriteLine(Environment.Version);
var dbContextFactory = new OracleContextFactory(supportAmbientTransaction: false);
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
var tasks = new List<Task>();
var dbContext1 = dbContextFactory.Create();
var book1 = await dbContext1.Books.Where(x => x.Id == 1).FirstAsync();
book1.UpdateCount++;
dbContext1.Update(book1);
tasks.Add(dbContext1.SaveChangesAsync());
//await dbContext1.SaveChangesAsync();
var dbContext2 = dbContextFactory.Create();
var book2 = await dbContext2.Books.Where(x => x.Id == 2).FirstAsync();
book2.UpdateCount++;
dbContext2.Update(book2);
tasks.Add(dbContext2.SaveChangesAsync());
//await dbContext2.SaveChangesAsync();
await Task.WhenAll(tasks);
transaction.Complete();
}
Console.WriteLine("Done!");
}
}