gpt4 book ai didi

c# - Entity Framework Core悲观锁行表Mysql

转载 作者:行者123 更新时间:2023-12-03 21:12:23 24 4
gpt4 key购买 nike

例如,如何在 EF Core 中使用 sql 查询this._context.Person.FirstOrDefault(a => a.id==1).ForUpdate()SELECT * FROM person WHERE id = 1 FOR UPDATE;
在 EF 核心中,我发现使用 EF 核心([ConcurrencyCheck], with Fluent Api ".IsConcurrencyToken();") 实现乐观并发,但它没有解决我的问题

最佳答案

您可以使用 TransactionScopeSystem.Transactions

using (var scope = new TransactionScope())
{
var person = this._context.Person.FirstOrDefault(a => a.id==1);
person.Col1 = "John Doe";
this._context.Person.Update(person);

this._context.SaveChanges();
scope.Complete();
}

关于c# - Entity Framework Core悲观锁行表Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54408220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com