title: Data modified show old value when called after update
body: <p>In my app I have a method that updates the values of an item like this:</p>
  
  <pre><code>foreach (var orderDetailInfo in _order.mListOrderDetail)
  {
      OrderDetailInfo info = orderDetailInfo;
  
      var inventoryQry = from i in db.INVENTORY
                         where i.INVENT_IDE == info.mInventoryID
                         select i;
  
      INVENTORY originalItem = inventoryQry.Single();
  
      INVENTORY itemToModify = originalItem;
  
      itemToModify.INVENT_NB_IN_STOCK = (orderDetailInfo.mOrderDetailQuantity +
                                         originalItem.INVENT_NB_IN_STOCK);
  
      db.Entry(originalItem).CurrentValues.SetValues(itemToModify);
  
      db.SaveChanges();
  }
  </code></pre>
  
  <p>Now if I look in the table at the <code>originalItem</code>, is value is updated. Say that before being updated, its value was 4, and the <code>order</code> updated the quantity to 5.</p>
  
  <p>My problem is that when I load the data like this after the upper code has run (so, after I update the <code>INVENT_NB_IN_STOCK</code> column):</p>
  
  <pre><code>var inventoryQry = from inv in db.INVENTORY
                     where inv.INVENT_IDE == inventIDE
                     select inv;
  
  return inventoryQry.Single();
  </code></pre>
  
  <p>The item shows <strong>the last value it holded before building</strong>, and not the current value. In this case, the value would be 4, not 5. Why? Can anyone help me figure out my problem?</p>
  
  <p>Since it might be because of a huge method I make, I am posting here the entire method which contains the chunk of code displayed up here:</p>
  
  <pre><code>internal void ValidateSupplierOrder(OrderInfo _order, List&lt;OrderDetailInfo&gt; _listOldOrderDetails)
  {
      using (BlueBerry_MTGEntities db = new BlueBerry_MTGEntities())
      {
          using (TransactionScope scope = TransactionUtils.CreateTransactionScope())
          {
              try
              {
                  ORDERS orderToModify = DataConverter.OrderInfoToOrderDATA(_order);
  
                  var orderQry = from o in db.ORDERS
                                 where o.ORDER_IDE == _order.mOrderID
                                 select o;
  
                  ORDERS originalOrder = orderQry.Single();
  
                  // First step: we need to remove the old order details as they are no more related
                  // To the order we are currently adding.
                  foreach (var orderDetail in _listOldOrderDetails)
                  {
                      OrderDetailInfo detail = orderDetail;
  
                      var orderDetailQry = from od in db.ORDER_DETAIL
                                           where od.ORDER_DETAIL_IDE == detail.mOrderDetailID
                                           select od;
  
                      ORDER_DETAIL itemToRemove = orderDetailQry.SingleOrDefault();
  
                      db.ORDER_DETAIL.Remove(itemToRemove);
  
                      db.SaveChanges();
                  }
  
                  foreach (ORDER_DETAIL orderDetailToCreate in _order.mListOrderDetail.Select(DataConverter.OrderDetailInfoToOrderDetailDATA))
                  {
                      db.ORDER_DETAIL.Add(orderDetailToCreate);
  
                      db.SaveChanges();
                  }
  
                  foreach (var orderDetailInfo in _order.mListOrderDetail)
                  {
                      OrderDetailInfo info = orderDetailInfo;
  
                      var inventoryQry = from i in db.INVENTORY
                                         where i.INVENT_IDE == info.mInventoryID
                                         select i;
  
                      INVENTORY originalItem = inventoryQry.Single();
  
                      INVENTORY itemToModify = originalItem;
  
                      itemToModify.INVENT_NB_IN_STOCK = (orderDetailInfo.mOrderDetailQuantity +
                                                         originalItem.INVENT_NB_IN_STOCK);
  
                      db.Entry(originalItem).CurrentValues.SetValues(itemToModify);
  
                      db.SaveChanges();
                  }
  
                  db.Entry(originalOrder).CurrentValues.SetValues(orderToModify);
  
                  db.SaveChanges();
              }
              catch(Exception ex)
              {
                  throw new Exception(ex.Message);
              }
  
              scope.Complete();
          }
      }
  }
  </code></pre>