【发布时间】:2012-02-02 17:21:24
【问题描述】:
我有一个类似这样的代码:
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);
}
这不起作用,我已经测试了查询,并且在提交数据时它们可以有效地工作,但是当它没有提交时,它会出现不允许我检查脏读的问题,即使隔离级别设置为未提交。
我想弄清楚为什么我不能访问这些信息,因为我不能以任何方式将信息提交到我们的数据库,因为这是一种测试方法。
谢谢!
这就是全部内容
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"));
}
}
.....
【问题讨论】:
-
这是否触及某种数据库后端?如果是这样 - 哪一个?
-
我尝试重新格式化您的代码以提高可读性,但在这样做的过程中,我发现它没有任何意义。您正在设置
IsolationLevel而没有使用它。您已经声明了scope,但也没有使用它。您可以直接从 IDE 中复制代码,然后将其粘贴到问题中。然后突出显示它并按“代码”按钮。这样,SO 将完全按照从 IDE 中出来的方式美化您的代码。 -
我在 TransactionScope 构造函数上设置了隔离级别。
-
我不使用变量范围,因为我使用了 "using" ,但是,我将复制我的整个方法来展示。谢谢1
-
数据库后端是什么意思?唯一发生的事情是,当我尝试脏读时,我在事务中插入的数据没有出现,我不确定我是否理解了这个问题!
标签: c# c#-4.0 transactionscope isolation-level transaction-isolation