I have entity
public class Realtor
{
[Key]
public int Id { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Guid { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime Registration { get; set; }
[ForeignKey("Id")]
public int SubdivId { get; set; }
public Subdiv Subdiv { get; set; }
}
and context with OnModelCreating method
modelBuilder.Entity<Realtor>(real => {
real.Property<Guid>(p => p.Guid)
.HasDefaultValueSql("newsequentialid()");
real.Property<DateTime>(p => p.Registration)
.HasDefaultValueSql("getdate()");
real.HasOne(r => r.Subdiv)
.WithMany(s => s.Realtors)
.HasForeignKey(r => r.SubdivId);
});
I set default value for property Registration, but when I do an insert, I get Exception: cannot insert the value null into column Registration.