title: Attach entity in modified state without marking all properties dirty
body: <p>I'm trying to figure out how to mark specific properties of a detached entity as modified. If I do the following, it will mark all properties modified and the generated sql will update all columns.</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Sets the entity in the modified state.
  /// &lt;/summary&gt;
  /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
  /// &lt;param name="entity"&gt;The entity.&lt;/param&gt;
  void IDbContext.Modified&lt;T&gt;(T entity)
  {
      DbEntityEntry&lt;T&gt; entry = Entry(entity);
      if (entry.State == EntityState.Modified)
      {
          // if the state is already Modified we don't need to do anything else
          return;
      }
  
      if (entry.State == EntityState.Detached)
      {
          Set&lt;T&gt;().Attach(entity);
  
          //TODO: set specific properties modified instead of the the whole object.
          entry.State = EntityState.Modified;
      }
  }
  </code></pre>
  
  <p>How do I set only changed properties as Modified?</p>
  
  <p>I'm trying to use this in a class that implements <code>DbContext</code> that will be used by a generic repository. The goal is to automagically determine which properties have changed compared to the database values and then set those changed properties states to Modified. In my current implementation, the Modified method has no knowledge of the entity type, so I can't simply retrieve it with <code>context.Set&lt;T&gt;.Find(key)</code>.</p>
  
  <p>I suppose I could add an overload that accepts an <code>originalEntity</code> parameter, but I'd rather not if possible.</p>
  
  <pre><code>void IDbContext.Modified&lt;T&gt;(T entity, T originalEntity)
  {
      DbEntityEntry&lt;T&gt; entry = Entry(entity);
      if (entry.State == EntityState.Modified)
      {
          // if the state is already Modified we don't need to do anything else
          return;
      }
  
      if (entry.State == EntityState.Detached)
      {
          Set&lt;T&gt;().Attach(entity);
  
          entry.OriginalValues.SetValues(originalEntity);
      }
  }
  </code></pre>