【发布时间】:2013-02-13 16:09:12
【问题描述】:
var paymentAttempt = _auctionContext.PaymentAttempts.Where(o => o.Id == paymentAttemptId).SingleOrDefault();
if (paymentAttempt != null)
{
paymentAttempt.PaymentAttemptStatusId = (int)PaymentAttemptStatus.Defunct;
paymentAttempt.PaymentAttemptStatus = _auctionContext.PaymentAttemptStatuses.Where(pas => pas.Id == paymentAttempt.PaymentAttemptStatusId).First();
var relevantWinningBidsTotalPrices = _auctionContext.GetWinningBidsTotalPricesForPaymentAttempt(paymentAttemptId).ToArray();
foreach (var winningBid in relevantWinningBidsTotalPrices)
{
winningBid.Locked = false;
_auctionContext.UpdateObject(winningBid);
}
_auctionContext.SaveChanges();
}
在上面的代码之后
_auctionContext.SaveChanges();
被称为winningBid 会按预期更新,但paymentAttempt 不会。为什么是这样?这真的很令人沮丧。也没有错误。如果出现 EF 没有跟踪对象或类似的问题,我预计会发生故障,但没有发生此类错误。
【问题讨论】:
-
使用 Attach 将修改后的实体放入上下文中。保存之前。上下文不知道你在说什么。
标签: c# entity-framework