title: Ignore one property on update Entity Framework
body: <p>I'm working with .NET C# and Entity Framework.</p>
  
  <p>I have a situation where I need to update an object in the database but I'll keep one property untouched. I'd like to know is it possible to do that?</p>
  
  <p>Take the following class for example:</p>
  
  <pre><code>public class Person
  {
      public int PersonId { get; set; }
      public string Name{ get; set; }
      public int Age { get; set; }
      public DateTime CreationDate { get; set; }
  }
  </code></pre>
  
  <p>So I would provide a HTML form in a page for the client to edit a person. 
  Example: </p>
  
  <pre><code>&lt;form&gt;
      &lt;input type="hidden" id="PersonId" value="1" /&gt;
      &lt;input type="text" id="Name" value="Cesar" /&gt;
      &lt;input type="text" id="Age " value="28" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Then I'd grab the values and send to the repository to update that Person. But it does not make sense updating CreationDate, and I don't want to provide that possibility.</p>
  
  <p>So I could do it in 2 different ways.</p>
  
  <p>1) I could put it in the form as a hidden field and post it back. (but as I said I don't want to provide that possibility)</p>
  
  <p>2) In the repository get the Person, update it's fields and leave CreationDate date the same and then save it:</p>
  
  <pre><code>void UpdatePerson(Person p){
      var person = db.Persons.Find(PersonId);
  
      person.Name = p.Name;
      person.Age = p.Age;
  
      db.Persons.Attach(person);
      db.Entry(person).State = EntityState.Modified;
      db.SaveChanges();        
  }
  </code></pre>
  
  <p>I'd like to know a way that I could just pass "p" to the context and update it leaving CreationDate the way it is.</p>
  
  <p>I hope I was clearer.</p>
  
  <p>I'm sorry about the lack of information in the first post.</p>
  
  <p>Thank you for your help.</p>