2017-07-19 66 views
0

在我的C++程序中,我遇到了我的程序出現問題,我一次通過數據庫運行了太多事情,並且出現錯誤。我怎樣才能解決這個問題?數據庫有問題

+0

也許你應該等待每個'this.ptoDataService.update(this.ptoData [1]) ;'完成之後再發送下一個。 –

+0

'this.ptoDataService.update(this.ptoData [i]);'return? –

+0

如果你可以讓''''update'''函數在返回結果後調用一些回調函數,那麼你可以對函數進行遞歸回調,如果列表是空的,那麼你會傳遞一個項目列表。更新第一個條目並調用相同的函數減去回調中的更新值 – LLL

回答

2

鑑於您已使用服務器端代碼更新了代碼。這是解決死鎖問題的一種方法。

首先您需要默認了解事務的實體框架隔離級別是可序列化的。這裏有SQL server Isolation levels.

它指出了序列化的一些信息:

  • 沒有其他事務都不能修改已經由當前事務,直到當前事務完成了讀取數據。

所以你需要做的是改變你的EF事務範圍的隔離級別爲快照例如:

using (var scope = new TransactionScope(TransactionScopeOption.Required, new 
TransactionOptions { IsolationLevel= IsolationLevel.Snapshot })) 
{ 
    // do something with EF here 
    scope.Complete(); 
} 
0
recordPayroll(): void { 
    return Observable.of(this.ptoData).mergeMap(ptoDataItem => { 
    if (this.ptoDataItem.date < this.date && this.ptoDataItem.type != "Uncharged") { 
     this.ptoDataItem.inPR = true; 
     return this.ptoDataService.update(this.ptoDataItem); 
    } 
    return Observable.empty(); 
    } 
} 

沒有保證,這將工作。我自己不使用TS,也不習慣RxJS。