title: Code First default DateTime not working
body: <p>I have a DateTime field that I want to set to a default value whenever a record is entered into that table (it is basically a DateCreated field).  This is my code </p>
  
  <pre><code>public partial class User
      {
          public User()
          {
              this.DateCreated = DateTime.Now; //set default value
              Roles = new HashSet&lt;Role&gt;();
          }
  
          public ICollection&lt;Role&gt; Roles { get; set; } //many to many relationship
  
          public int UserId { get; set; }
          public string FirstName { get; set; }
          public string Surname { get; set; }
          public string Username { get; set; }
          public string Password { get; set; }
          public string City { get; set; }
  
          //foreign key
          public int CountryId { get; set; }
          //navigation properties
          public virtual Country Country { get; set; }
  
          //foreign key
          public int LanguageId { get; set; }
          //navigation properties
          public virtual Language Language { get; set; }
  
          public string EmailAddress { get; set; }
          public long FacebookId { get; set; }
          public DateTime DateCreated { get; set; }
      } }
  
      public class UserConfiguration : EntityTypeConfiguration&lt;User&gt;
      {
          public UserConfiguration()
          {
              ToTable("Users", schemaName: "Main");
  
              HasKey(s =&gt; s.UserId);
  
              Property(p =&gt; p.FirstName)
                  .IsRequired().HasMaxLength(50); //translates to non-nullable     
  
              Property(p =&gt; p.Surname)
                  .IsRequired().HasMaxLength(50);
  
              Property(p =&gt; p.Username)
                  .IsRequired().HasMaxLength(20);
  
              Property(p =&gt; p.Password)
                  .IsRequired().HasMaxLength(20);
  
              Property(p =&gt; p.City)
                  .IsOptional().HasMaxLength(50); //not required
  
              Property(p =&gt; p.LanguageId)
                  .IsRequired();
  
              Property(p =&gt; p.EmailAddress)
                  .IsRequired().HasMaxLength(50);
  
              Property(p =&gt; p.FacebookId)
                  .IsOptional();
  
              Property(p =&gt; p.DateCreated) 
                  .IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
              //attribute ensures that DateCreated only gets saved to the database when you are adding a 
              //row, not when you are saving
          }
      }
  
      context.Users.Add(new User
                  {
                      FirstName = "Test",
                      Surname = "User",
                      Username = "testuser72",
                      Password = "testuser72",
                      City = "London",
                      CountryId = context.Countries.Single(d =&gt; d.CountryName == "United Kingdom").CountryId,
                      LanguageId = context.Languages.Single(d =&gt; d.LanguageName == "English").LanguageId,
                      EmailAddress = "testuser@yahoo.co.uk",
                      Roles = new Role[] { context.Roles.Single(r =&gt; r.RoleName == "Content Editor"), context.Roles.Single(s =&gt; s.RoleName == "User") }
                  });
  </code></pre>
  
  <p>Why when I try to add a user using the code above why do I get the error 'Cannot insert the value NULL into column 'DateCreated', table 'Main.Users'; 
  column does not allow nulls. INSERT fails.'?</p>