我有一個是這樣的代碼:
「髒讀」與READUNCOMMITTED隔離級別設置事務範圍中不工作
using (TransactionScope scope =
new TransactionScope(TransactionScopeOption.Required), new TransactionOptions)
{
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted }))
// "dirty" read for test purposes , to see if my
// select will actually select the information I just inserted
actual = target.GetCostCentersRates(accountId);
}
這不工作,我已經測試查詢和他們有效地工作時數據被提交,但是當它沒有提交時,它提出了不允許我檢查髒讀的問題,即使隔離級別設置爲readuncommitted。 我想知道爲什麼我不能訪問這些信息,因爲我不能以任何方式將信息提交給我們的數據庫,因爲這是一種測試方法。
謝謝!
這裏是整個事情
public void GetCostCentersRatesTest()
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommited }))
{
//Arrange
BRL.AdministrativeArea.SystemClientBusinessRole systemClient = new BRL.AdministrativeArea.SystemClientBusinessRole();
int systemClientId = systemClient.InsertSystemClient(systemClientInfo).systemClientId;
BRL.BRLProperties.systemClientId = systemClientId;
employeeInfo.multiCompaniesInfo.systemClientId = systemClientId;
int stateId = 1;
int cityId = 1;
int functionId = 1;
employeeInfo.stateId = stateId;
employeeInfo.cityId = cityId;
employeeInfo.functionId = functionId;
int employeeId = employees.InsertEmployeers(employeeInfo);
BRL.BRLProperties.employeeId = employeeId;
IActionReturnInfo actionAccount = (accounts.InsertAccountPlan(accountPlanInfo));
int accountId = Convert.ToInt32(actionAccount.UpdateDataSourceList[0].ToString());
clientInfo.stateId = stateId;
clientInfo.cityId = cityId;
clientInfo.stateIdCorrespondency = stateId;
clientInfo.cityIdCorrespondency = cityId;
clientInfo.stateIdDelivery = stateId;
clientInfo.cityIdDelivery = cityId;
clientInfo.multiCompaniesInfo.systemClientId = systemClientId;
clientInfo.multiCompaniesInfo.employeeId = employeeId;
int clientId;
clients.InsertClient(clientInfo, out clientId);
centerCostInfo.systemClientId = systemClientId;
centerCostInfo.clientId = clientId;
centerCostInfo.employeeId = employeeId;
centerCostInfo.directorID = employeeId;
centerCostInfo.managerID = employeeId;
centerCostInfo.multiCompaniesInfo.systemClientId = systemClientId;
centerCostInfo.multiCompaniesInfo.employeeId = employeeId;
IActionReturnInfo action = new CenterCostsBusinessRole().InsertCostCenter(centerCostInfo);
int centerCostId = Convert.ToInt32(action.UpdateDataSourceList[0].ToString());
rate.accountId = accountId;
rate.centerCostId = centerCostId;
costCenterRates.Add(rate);
int costCenterRateId;
AccountBusinessRole target = new AccountBusinessRole();
DataSet actual;
IActionReturnInfo costCenterRateAction = accounts.InsertCenterCostRates(costCenterRates);
costCenterRateId = Convert.ToInt32(costCenterRateAction.UpdateDataSourceList[0].ToString());
//Act
actual = target.GetCostCentersRates(accountId);
//Assert
Assert.IsTrue(FindInDataset(costCenterRateId, actual, "ACCOUNTID"));
}
}
.....
這是打到某種數據庫後端?如果是這樣 - 哪一個? – RQDQ 2012-02-02 17:26:06
我試圖重新格式化您的代碼的可讀性,並在這樣做時,我發現它沒有任何意義。你正在設置'IsolationLevel'而不是使用它。你已經聲明瞭'範圍',但是沒有使用它。你能直接從IDE中複製代碼,並將其粘貼到問題中。然後突出顯示它並按下「代碼」按鈕。這樣,SO會完全按照它從IDE發出的方式來優化代碼。 – 2012-02-02 17:29:22
我在TransactionScope構造函數上設置隔離級別。 – 2012-02-02 17:36:05