Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何读取某些实体并使用事务通过并发锁定对其进行更改?_.net_Entity Framework_Concurrency_Transactions - Fatal编程技术网

.net 如何读取某些实体并使用事务通过并发锁定对其进行更改?

.net 如何读取某些实体并使用事务通过并发锁定对其进行更改?,.net,entity-framework,concurrency,transactions,.net,Entity Framework,Concurrency,Transactions,如何使用事务通过并发锁定读取某些实体并更改其属性 例如,我必须这样做: ` ` 如何使多个线程不能仅通过事务中断它?我不能使用乐观并发方式(添加一些时间戳) 如果使用隔离级别可序列化的事务,则会导致线程死锁 // repository has access to database context var account = _accountRepository.Get(accountId); if(account.Balance > product.Price){ // Thre

如何使用事务通过并发锁定读取某些实体并更改其属性 例如,我必须这样做:

`

`

如何使多个线程不能仅通过事务中断它?我不能使用乐观并发方式(添加一些时间戳) 如果使用隔离级别可序列化的事务,则会导致线程死锁

// repository has access to database context
var account = _accountRepository.Get(accountId); 
if(account.Balance > product.Price){
    // Thread.Sleep(time);
    account.Balance -= product.Price;
}
_accountRepository.Update(account);