为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】: --03134284194-20240621-232765-20108
【操作系统】:docker
【CPU】: 虚拟机
【SDK】: <PackageReference Include="DM.Microsoft.EntityFrameworkCore" Version="7.0.0.20986" />
【问题描述】:
using (var transcation = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
db.Add(new Blog { Url = "111",Jdata = "[515895181640208384]"});
db.SaveChanges();
var postList1 = new List<Post>();
postList1.Add(new Post { Title = "11Hello World", Content = "I wrote an app using EF Core!" });
postList1.Add(new Post { Title = "12Hello World", Content = "I wrote an app using EF Core!" });
postList1.Add(new Post { Title = "13Hello World", Content = "I wrote an app using EF Core!" });
var postList2 = new List<Post>();
postList2.Add(new Post { Title = "21Hello World", Content = "I wrote an app using EF Core!" });
postList2.Add(new Post { Title = "22Hello World", Content = "I wrote an app using EF Core!" });
postList2.Add(new Post { Title = "23Hello World", Content = "I wrote an app using EF Core!" });
var postList3 = new List<Post>();
postList3.Add(new Post { Title = "31Hello World", Content = "I wrote an app using EF Core!" });
postList3.Add(new Post { Title = "32Hello World", Content = "I wrote an app using EF Core!" });
postList3.Add(new Post { Title = "33Hello World", Content = "I wrote an app using EF Core!" });
foreach (var p1 in postList1)
{
db.Add(p1);
}
db.SaveChanges();
foreach (var p2 in postList2)
{
db.Add(p2);
}
db.SaveChanges();
foreach (var p3 in postList3)
{
db.Add(p3);
}
db.SaveChanges();
transcation.Complete();
}
// 关联类
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
[Column(TypeName = "Json")]
public String Jdata { get; set; }
public List<Post> Posts { get; } = new();
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
** 相关日志(内容最大值影响,提供部分关键)😗*
--- 此处省略部分内容--
2024-08-15 11:29:55.213 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) TRX: START
2024-08-15 11:29:55.232 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) Load para: 1 rows
2024-08-15 11:29:55.232 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) PARAMS(SEQNO, TYPE, DATA)={(0, VARCHAR, '[515895181640208384, 516610545822994432, 515899270205804544]'), (1, TEXT, )}
2024-08-15 11:29:55.232 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) trx[77094] alloc pseg page[0, 991], page_lsn[20079142], n_pages[1]
2024-08-15 11:29:55.233 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) [CAL]
INSERT INTO "Blogs" ("Jdata", "Url")
VALUES (:p0, :p1);
SELECT "BlogId"
FROM "Blogs"
WHERE sql%ROWCOUNT = 1 AND "BlogId" = scope_identity();
EXECTIME: 0(ms) EXEC_ID: 3002.
2024-08-15 11:29:55.282 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) MORE_RESULT
--- 此处省略部分内容--
2024-08-15 11:29:55.213 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) TRX: START
2024-08-15 11:29:55.232 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) Load para: 1 rows
2024-08-15 11:29:55.232 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) PARAMS(SEQNO, TYPE, DATA)={(0, VARCHAR, '[515895181640208384, 516610545822994432, 515899270205804544]'), (1, TEXT, )}
2024-08-15 11:29:55.232 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) trx[77094] alloc pseg page[0, 991], page_lsn[20079142], n_pages[1]
2024-08-15 11:29:55.233 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) [CAL]
INSERT INTO "Blogs" ("Jdata", "Url")
VALUES (:p0, :p1);
SELECT "BlogId"
FROM "Blogs"
WHERE sql%ROWCOUNT = 1 AND "BlogId" = scope_identity();
EXECTIME: 0(ms) EXEC_ID: 3002.
2024-08-15 11:29:55.282 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:0x7f126812f540 appname: ip:::ffff:192.168.20.11) MORE_RESULT
--- 此处省略部分内容--
2024-08-15 11:29:57.623 (EP[0] sess:0x7f12700114a8 thrd:5445 user:TEST_MES trxid:77095 stmt:NULL appname:) TRX: START
2024-08-15 11:29:57.623 (EP[0] sess:0x7f12700114a8 thrd:5445 user:TEST_MES trxid:77095 stmt:0x7f127000d840 appname: ip:::ffff:192.168.20.11) [DDL] set schema HANS
2024-08-15 11:29:57.627 (EP[0] sess:0x7f12700114a8 thrd:5445 user:TEST_MES trxid:77095 stmt:0x7f127000d840 appname: ip:::ffff:192.168.20.11) [DDL] set schema HANS EXECTIME: 3(ms) EXEC_ID: 3100.
2024-08-15 11:29:57.629 (EP[0] sess:0x7f12700114a8 thrd:5445 user:TEST_MES trxid:77095 stmt:0x7f127000d840 appname: ip:::ffff:192.168.20.11) [ORA]:
INSERT INTO "Posts" ("BlogId", "Content", "Title")
VALUES (:p0, :p1, :p2);
SELECT "PostId"
FROM "Posts"
WHERE sql%ROWCOUNT = 1 AND "PostId" = scope_identity();
INSERT INTO "Posts" ("BlogId", "Content", "Title")
VALUES (:p3, :p4, :p5);
SELECT "PostId"
FROM "Posts"
WHERE sql%ROWCOUNT = 1 AND "PostId" = scope_identity();
INSERT INTO "Posts" ("BlogId", "Content", "Title")
VALUES (:p6, :p7, :p8);
SELECT "PostId"
FROM "Posts"
WHERE sql%ROWCOUNT = 1 AND "PostId" = scope_identity();
--- 此处省略部分内容
EXECTIME: 0(ms) EXEC_ID: 3201.
2024-08-15 11:29:59.611 (EP[0] sess:0x7f12780114a8 thrd:5447 user:TEST_MES trxid:77096 stmt:0x7f127800d840 appname: ip:::ffff:192.168.20.11) MORE_RESULT
2024-08-15 11:29:59.612 (EP[0] sess:0x7f12780114a8 thrd:5447 user:TEST_MES trxid:77096 stmt:0x7f127800d840 appname: ip:::ffff:192.168.20.11) MORE_RESULT
2024-08-15 11:29:59.612 (EP[0] sess:0x7f12780114a8 thrd:5447 user:TEST_MES trxid:77096 stmt:0x7f127800d840 appname: ip:::ffff:192.168.20.11) MORE_RESULT
2024-08-15 11:29:59.613 (EP[0] sess:0x7f12780114a8 thrd:5447 user:TEST_MES trxid:77096 stmt:NULL appname:) [LGN] FREE SESSION
2024-08-15 11:29:59.613 (EP[0] sess:0x7f12780114a8 thrd:5447 user:TEST_MES trxid:77096 stmt:NULL appname:) TRX: ROLLBACK
2024-08-15 11:29:59.613 (EP[0] sess:0x7f12780114a8 thrd:5447 user:TEST_MES trxid:77096 stmt:NULL appname:) trx[77096]: pseg_reset_last_page free pseg page (0, 799)
--- 此处省略部分内容
2024-08-15 11:30:01.595 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:0x7f123000d840 appname: ip:::ffff:192.168.20.11) Load para: 1 rows
2024-08-15 11:30:01.595 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:0x7f123000d840 appname: ip:::ffff:192.168.20.11) PARAMS(SEQNO, TYPE, DATA)={(0, INTEGER, 0), (1, TEXT, ), (2, TEXT, ), (3, INTEGER, 0), (4, TEXT, ), (5, TEXT, ), (6, INTEGER, 0), (7, TEXT, ), (8, TEXT, )}
2024-08-15 11:30:01.596 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:NULL appname:) trx[77097] alloc pseg page[0, 831], page_lsn[20079222], n_pages[1]
2024-08-15 11:30:01.596 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:0x7f123000d840 appname: ip:::ffff:192.168.20.11) [CAL]
INSERT INTO "Posts" ("BlogId", "Content", "Title")
VALUES (:p0, :p1, :p2);
SELECT "PostId"
FROM "Posts"
WHERE sql%ROWCOUNT = 1 AND "PostId" = scope_identity();
INSERT INTO "Posts" ("BlogId", "Content", "Title")
VALUES (:p3, :p4, :p5);
SELECT "PostId"
FROM "Posts"
WHERE sql%ROWCOUNT = 1 AND "PostId" = scope_identity();
INSERT INTO "Posts" ("BlogId", "Content", "Title")
VALUES (:p6, :p7, :p8);
SELECT "PostId"
FROM "Posts"
WHERE sql%ROWCOUNT = 1 AND "PostId" = scope_identity();
EXECTIME: 0(ms) EXEC_ID: 3301.
2024-08-15 11:30:01.599 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:0x7f123000d840 appname: ip:::ffff:192.168.20.11) MORE_RESULT
2024-08-15 11:30:01.601 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:0x7f123000d840 appname: ip:::ffff:192.168.20.11) MORE_RESULT
2024-08-15 11:30:01.602 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:0x7f123000d840 appname: ip:::ffff:192.168.20.11) MORE_RESULT
2024-08-15 11:30:01.603 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:NULL appname:) [LGN] FREE SESSION
2024-08-15 11:30:01.603 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:NULL appname:) TRX: ROLLBACK
2024-08-15 11:30:01.603 (EP[0] sess:0x7f12300114a8 thrd:5452 user:TEST_MES trxid:77097 stmt:NULL appname:) trx[77097]: pseg_reset_last_page free pseg page (0, 831)
2024-08-15 11:30:04.758 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) MSG: COMMIT
2024-08-15 11:30:04.758 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) TRX: COMMIT
2024-08-15 11:30:04.758 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:77094 stmt:NULL appname:) trx[77094]: pseg_page_free_for_insert_only_trx free pseg page (0, 991), page_lsn = 20079255
2024-08-15 11:30:04.759 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:0 stmt:NULL appname:) TRX: COMMIT LSN[20079254]
2024-08-15 11:30:04.761 (EP[0] sess:0x7f12681318c8 thrd:5440 user:TEST_MES trxid:0 stmt:NULL appname:) [LGN] FREE SESSION
现象:
我的问题:
根据sqllog日志可得出针对posts和blogs表的操作,是由2个不同线程处理的,所以肯定是由2个不同事务处理,在处理posts表的线程日志中,可看到有相关ddl操作,达梦ddl操作是默认会自动提交的,可能就是这里导致了TransactionScope方法的失效和数据的回滚
