title: An object with the same key already exists in the ObjectStateManager. when using AsNoTracking
body: <p>There are many errors here in SO, but this scenario I think its different.</p>
  
  <p>I had some code that was working fine, I update one entity, etc.  But the problem is that it was being cached, when I disabled caching with AsNoTracking(), then it started to throw this exception;</p>
  
  <p>What I do its the following:
  1. In the page I get a EcoBonusRequest.
  2.  The user clicks a button and it modifies the currentstatus proeprty, and it addsa a list item to a collection of workflowhistories, (an associated collection of the ecobonusrequestobject).
  3. I call the udpate method, setting state to modified, here it throwed the exception.</p>
  
  <p>Here is my code></p>
  
  <p><strong>EcoBonusRequestRepository.cs</strong></p>
  
  <pre><code>public void UpdateEcoBonusRequest(EcoBonusRequest ecoBonusRequest)
              {
                  _context.EcoBonusRequests.Attach(ecoBonusRequest);
                  _context.Entry(ecoBonusRequest).State = EntityState.Modified;
              }
  </code></pre>
  
  <p><strong>EcoBonusRequestBL</strong></p>
  
  <pre><code>public void Update(EcoBonusRequest ecoBonusRequest)
          {
              DALFacade.UpdateEcoBonusRequest(ecoBonusRequest);
          }
  </code></pre>
  
  <p><strong>EcoBonusRequest Page</strong></p>
  
  <pre><code>public void ChangeStatus(EcoBonusRequest ecoBonusRequest, string stepname, string who, string choosenoption)
          {
  
              ecoBonusRequest.WorkflowHistories = new List&lt;WorkflowHistory&gt;
                                                     {
                                                         new WorkflowHistory()
                                                             {
                                                                 Date = DateTime.Now,
                                                                 What = choosenoption,
                                                                 StepName = stepname,
                                                                 Who = who
                                                             }
                                                     };
  
              ecoBonusRequest.CurrentStatus = _currentStepBlo.StepName;
              var ecoBonusRequestBL = new EcoBonusRequestBL();
              ecoBonusRequestBL.Update(ecoBonusRequest);
          }
  </code></pre>
  
  <p>This is how I get the object first: (I am not going to paste all code from all layers here)</p>
  
  <pre><code>protected override void OnInit(EventArgs e)
          {
              var requestBaseId = RequestBaseId;
              if (requestBaseId != null)
              {
                  EcoBonusRequest request = GetDBRequest(requestBaseId.Value);
  </code></pre>
  
  <p>In the dal</p>
  
  <pre><code>public IQueryable&lt;EcoBonusRequest&gt; FindEcoBonusRequests(System.Linq.Expressions.Expression&lt;Func&lt;EcoBonusRequest, bool&gt;&gt; predicate)
              {
                  return _context.EcoBonusRequests.AsNoTracking().Where(predicate);
              }
  </code></pre>