所有項目我有這樣的方法:的UnitOfWork不更新基於條件
public bool UpdateOfficeApprovers(IList<int> invoiceLinesToUpdate, int userId)
{
foreach (var invoiceLineId in invoiceLinesToUpdate)
{
var invoiceLine = _unitOfWork.InvoiceLineRepository.Get(invoiceLineId);
invoiceLine.OfficeUserId = userId;
if (!invoiceLine.HasTwoUniqueApprovers)
{
// do something here to avoid this line being updated
}
}
_unitOfWork.Save();
return hasUniqueApprovers;
}
我想在這裏做的是通過所有的invoiceLines並更新其OfficeUserId。然而,有狀態HasTwoUniqueApprovers
,如果這是false
我不想更新此invoiceLine只是離開它。
好太行:
invoiceLine.OfficeUserId = userId;
將更新實體狀態EntityState.Modified
是否正確?
所以當:
_unitOfWork.Save();
這將保存所有的invoiceLInes因爲它節省了一切:
EntityState.Modified
那麼我現在想知道的是如何被更新阻止某些invoiceLInes 。
所以當invoiceLine符合條件如何設置它,所以它不會被更新?
檢查範圍和縮進,你有一個錯誤。我編輯了某種方式。 – abatishchev 2012-04-11 11:08:40