title: How to create a default constraint in EF code-first and Azure?
body: <p>I have the following code-first Entity Framework code that I'm using with Azure Mobile services:</p>
  
  <pre><code>public class BookContext : DbContext
  {
  private const string connectionStringName = "Name=MS_TableConnectionString";
  
  public BookContext() : base(connectionStringName) { } 
  
  // The collections queried directly.
  public DbSet&lt;Book&gt; Books{ get; set; }
  
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      // Standard code to add the "service" columns such as CreatedAt, UpdatedAt, and Deleted.
      modelBuilder.Conventions.Add(
          new AttributeToColumnAnnotationConvention&lt;TableColumnAttribute, string&gt;(
              "ServiceTableColumn", (property, attributes) =&gt; attributes.Single().ColumnType.ToString()));
  
      // Add a default value 0 on the Deleted column. The following code does not work.
      modelBuilder.Entity&lt;Book&gt;()
                  .Property(p =&gt; p.Deleted)
                  .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
  }
  }
  </code></pre>
  
  <p>As noted above, the code is supposed to add a default constraint on the Deleted column, but it does not do anything. I'd like to achieve an equivalent of the following SQL statement as the EF code-first:</p>
  
  <pre><code>ALTER TABLE dbo.Books ADD CONSTRAINT DF_BooksDeleted DEFAULT 0 FOR Deleted
  </code></pre>
  
  <p>Apparently, I must be doing something wrong. Could anyone point me in the right direction?</p>