title: Update hierarchy model in Entity Framework
body: <p>I have two model classes:</p>
  
  <p>Request:</p>
  
  <pre><code>public partial class Request
  {
      public long Id { get; set; }
      public string Username { get; set; }
      public string Description { get; set; }
      public System.DateTime CreateDate { get; set; }
      public long DeviceId { get; set; }
      public bool IsFinalized { get; set; }
      public Nullable&lt;long&gt; ParentId { get; set; }
      public virtual Device Device { get; set; }
  }
  </code></pre>
  
  <p>Device:</p>
  
  <pre><code>public partial class Device
  {
      public Device()
      {
          this.Requests = new List&lt;Request&gt;();
      }
  
      public long Id { get; set; }
      public string Serial { get; set; }
      public string AssetNumber { get; set; }
      public System.DateTime CreatedDate { get; set; }
      public virtual ICollection&lt;Request&gt; Requests { get; set; }
  }
  </code></pre>
  
  <p>I have to update the models I use this method</p>
  
  <pre><code>    public void Update(RequestViewModel viewModel)
      {
          var entity = _mappingEngine.Map&lt;Request&gt;(viewModel);
          _requests.Attach(entity);
          _uow.Entry(entity).State = EntityState.Modified;
      }
  </code></pre>
  
  <p>but only <code>Request</code> model is updated after calling the <code>Update</code> method. I want to update both models. Please help me.</p>