例如,如何在 EF Core 中使用 sql 查询
this._context.Person.FirstOrDefault(a => a.id==1).ForUpdate()
SELECT * FROM person WHERE id = 1 FOR UPDATE;
在 EF core 中,我发现 Implementing optimistic concurrency with EF Core( [ConcurrencyCheck], with Fluent Api ".IsConcurrencyToken();"),但它没有解决我的问题
你可以使用TransactionScope下System.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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1395 次 |
| 最近记录: |