title: Why I'm gettin Cannot insert the value NULL into computed column?
body: <p>I'm using EF-Code First and this is my model with Data Annotation:</p>
  
  <pre><code>public int Count { get; set; }
  public int Fee { get; set; }
  
  [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
  public int Total { get; set; }
  </code></pre>
  
  <p>Or like this:</p>
  
  <pre><code>[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
  
  public int Total
  {
      get { return Fee * Count; }
      private set{}
  }
  </code></pre>
  
  <p>When I want to create a new record I'm getting the following error:</p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'Total'; column does not allow nulls. INSERT fails.
    The statement has been terminated.</p>
  </blockquote>
  
  <p>As you can see I'm getting the correct computed value in the Create Action Method with model binder:</p>
  
  <p><a href="https://i.stack.imgur.com/X0r3e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X0r3e.png" alt="enter image description here"></a></p>
  
  <p>By removing the <code>DatabaseGenerated(DatabaseGeneratedOption.Computed)</code> and set the computed value from my code it works fine and I see the updated total in the database. But my question is if I can do this without <code>DatabaseGenerated(DatabaseGeneratedOption.Computed)</code> so what's the <code>DatabaseGenerated(DatabaseGeneratedOption.Computed)</code> usage?</p>
  
  <p>This works:</p>
  
  <pre><code>public int Total
  {
      get { return Fee * Count; }
      private set{}
  }
  </code></pre>