title: Exclude Property on Update in Entity Framework
body: <p>I've been looking for a proper way to mark a property to NOT be changed when updating a model in MVC.</p>
  
  <p>For example, let's take this small model:</p>
  
  <pre><code>class Model
  {
      [Key]
      public Guid Id {get; set;}
      public Guid Token {get; set;}
  
      //... lots of properties here ...
  }
  </code></pre>
  
  <p>then the edit method MVC creates looks like this:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(Model model)
  {
      if (ModelState.IsValid)
      {
          db.Entry(model).State = EntityState.Modified;
          db.SaveChanges();
          return RedirectToAction("Index");
      }
      return View(model);
  }
  </code></pre>
  
  <p>now if my View does not contain the Token, it will be nullified through that edit.</p>
  
  <p>I'm looking for something like this: </p>
  
  <pre><code>db.Entry(model).State = EntityState.Modified;
  db.Entry(model).Property(x =&gt; x.Token).State = PropertyState.Unmodified;
  db.SaveChanges();
  </code></pre>
  
  <p>The best way so far I found is to be inclusive and set all properties I want included by hand, but I really only want to say which ones to be excluded.</p>