title: Update variable in foreach
body: <p>I have an issue related to updating an object by reference and not sure exactly what is going on.</p>
  
  <p>I need to delete a list of rules and for logging I need to load another field </p>
  
  <pre><code>ruleItem.ReferencedItemValue = eventEntity.Title;
  </code></pre>
  
  <p>When</p>
  
  <pre><code> builder.LogDelete(showRule, showRuleResource.ToAuditLog(), "Logic Rule");
  </code></pre>
  
  <p>is called the <code>ReferencedItemValue</code> is not populated.</p>
  
  <p>Any ideas, suggestions, alternatives?
  Thanks</p>
  
  <p>CODE:</p>
  
  <pre><code>public void DeleteCustomLogicRule(int[] ruleIds){
      var rules = uow.Context.ShowRules.Where(sr =&gt; ruleIds.Contains(sr.Id)).ToList();
      if (rules.Any())
      {
          var showId = rules.FirstOrDefault().ShowId;
          var builder = AuditBuilder.FromShowId(showId);
          rules.ForEach(showRule =&gt;
          {
              var showRuleResource = ToShowRuleResource(showRule);
              FillReferenceValue(showRuleResource);
              builder.LogDelete(showRule, showRuleResource.ToAuditLog(), "Logic Rule");
              });
          uow.Context.SaveChanges();
          builder.ToDatabase();
      }
  }
  
  private void FillReferenceValue(ShowRuleResource showRuleResource)
  {
      foreach (var ruleItem in showRuleResource.ItemsPredicateAppliesTo.ToList())
      {
          FillRuleItem(ruleItem);
      }
  }
  
  private void FillRuleItem(RuleItemResource ruleItem)
  {
      var eventEntity = uow.Context.Events.FirstOrDefault(e =&gt; e.Id == ruleItem.ReferencedItemId.Value);
      if (eventEntity != null)
      ruleItem.ReferencedItemValue = eventEntity.Title;
  }
  </code></pre>