这里的状态是我的代码基础提供失败的打开/操作是无效的交易
public static string UpdateEmptyCaseRevierSet() {
string response = string.Empty;
using (System.Transactions.TransactionScope tran = new System.Transactions.TransactionScope()) {
using (var db = new Entities.WaveEntities()) {
var maxCaseReviewersSetID = db.CaseReviewerSets.Select(crs => crs.CaseReviewersSetId).Max();
var emptyCHList = db.CaseHistories.Where(ch => ch.CaseReviewersSetID == null && ch.IsLatest == true && ch.StatusID != 100).ToList();
for(int i=0; i < emptyCHList.Count; i++) {
var emptyCH = emptyCHList[i];
var newCaseReviewerSET = new Entities.CaseReviewerSet();
newCaseReviewerSET.CreationCHID = emptyCH.CHID;
db.CaseReviewerSets.Add(newCaseReviewerSET);
emptyCH.CaseReviewerSet = newCaseReviewerSET;
}
db.SaveChanges();
}
tran.Complete();
}
return response;
}
异常的occures“db.SaveChanges()”
我看到另一篇文章与"it seems I cannot have two connections opened to the same database with the TransactionScope block."
相同的错误消息,但我不认为这与我的情况有任何关系。
此外总共插入和更新的记录数是2700,女巫实际上并不是那么多。但是要完成for语句需要花费相当多的时间(大约10分钟左右)。由于for语句中发生的所有事情实际上都发生在内存中,有人可能会解释为什么这会花费这么长时间?
试试用增'交易时间' – Sagar