[英]Entity Framework Core pessimistic locking row table Mysql
How can I use sql query in EF Core as for example this._context.Person.FirstOrDefault(a => a.id==1).ForUpdate()
我如何在EF Core中使用sql查询,例如
this._context.Person.FirstOrDefault(a => a.id==1).ForUpdate()
SELECT * FROM person WHERE id = 1 FOR UPDATE;
in EF core I find Implementing optimistic concurrency with EF Core( [ConcurrencyCheck], with Fluent Api ".IsConcurrencyToken();"), but it not solved my problem 在EF核心中,我发现使用EF Core([ConcurrencyCheck]和Fluent Api“ .IsConcurrencyToken();”)实现开放式并发,但并没有解决我的问题
you can use TransactionScope
under System.Transactions
您可以在
System.Transactions
下使用TransactionScope
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();
}
To resolve my question i use this aproach: 为了解决我的问题,我使用以下方法:
this._context.Person.FromSql($"SELECT * FROM person WHERE id= { personId } FOR UPDATE").FirstOrDefaultAsync();
In Github has already been opened issue https://github.com/aspnet/EntityFrameworkCore/issues/6717 在Github中已经打开问题https://github.com/aspnet/EntityFrameworkCore/issues/6717
When this issue will resolved(closed), then we can do as I want 该问题解决(关闭)后,我们可以按照我的意愿做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.