您無法使用一個查詢執行更新。你甚至不能在SQL中這樣做,更不用說在LinQ中。你需要的是一項交易。 在事務中,您可以將兩個表記錄加載到變量中,更新它們的值並提交事務。
using (var transaction = new TransactionScope()) {
try {
record1 = (from r in myDataContext.Table1s where r.BId == myBid select r).FirstOrDefault();
record2 = (from r in myDataContext.Table2s where r.BId == myBid select r).FirstOrDefault();
// Perform your record updates here
var oldExpense = record2.Expense;
record2.Expense = newExpense;
record1.Amount += (newExpense - oldExpense);
myDataContext.SubmitChanges(); // if an exception occurs here, the transaction is aborted
transaction.Complete(); // commits the transaction
} catch (Exception ex) {
// TODO: Exception handling
}
}
非常感謝你,正是我所需要的 – fireBand 2010-04-26 18:51:56