DTC在我的機器上被禁用。我的理解是,這段代碼會失敗,因爲它在同一個事務中使用兩個數據上下文。那麼,它爲什麼會起作用? (注:這個我試過用.NET 3.5和.NET 4.0)爲什麼我的交易不會升級到DTC?
using (TransactionScope transactionScope = new TransactionScope())
{
UpdateEta();
UpdateBin();
transactionScope.Complete();
}
下面是被調用的方法DAL:
public static void UpdateBin(Bin updatedBin)
{
using (DevProdDataDataContext dataContext = new DevProdDataDataContext(ConnectionString))
{
BinRecord binRecord = (from bin in dataContext.BinRecords
where bin.BinID == updatedBin.BinId
select bin).FirstOrDefault();
binRecord.BinID = updatedBin.BinId;
binRecord.BinName = updatedBin.BinName;
dataContext.SubmitChanges();
}
}
public static void UpdateEta(Eta updatedEta)
{
using (DevProdDataDataContext dataContext = new DevProdDataDataContext(ConnectionString))
{
EtaRecord etaRecord = (from eta in dataContext.EtaRecords
where eta.ID == updatedEta.ID
select eta).FirstOrDefault();
etaRecord.ID = updatedEta.ID;
etaRecord.Title = updatedEta.Title;
dataContext.SubmitChanges();
}
}
大問題Horn先生。 – 2011-05-06 16:53:28