title: Entity Framework error: The field X is required
body: <p>I have the following class: </p>
  
  <pre><code>public class Foo
  {
          [Key] 
          public int ID { get; set; }
  
          [Required]
          [StringLength(100)]
          public string Name { get; set; }
  
          [Required]
          public float Quantity { get; set; } 
  }
  </code></pre>
  
  <p>and I'm using the following code to update the property <code>Quantity</code>:</p>
  
  <pre><code>  Foo f = new Foo {ID = 2, Quantity = 10}; // Updated object  
  
    DbSet dbSet = this.Set(f.GetType());
    dbSet.Attach(f);
    var be = Entry(f);
    be.Property("Quantity").IsModified = true;
  
    DBContext.SaveChanges();
  </code></pre>
  
  <p>However, the code produces an exception like this: </p>
  
  <blockquote>
    <p>"The field 'Name' is required"</p>
  </blockquote>
  
  <p>As far as I know the last piece of code should only update the field <code>Quantity</code> but it is taking into account the field <code>Name</code> as well.</p>
  
  <p>I could avoid this error by taking the object before the update </p>
  
  <pre><code>Foo f = DBContext.Foos.Single&lt;Foo&gt;( x =&gt; x.ID == 2);
  f.Quantity = 10; 
  DBContext.SaveChanges();
  </code></pre>
  
  <p>but I think that is not a good option because it will spend two database accesses. </p>
  
  <p>Any suggestions will be appreciated.  </p>