How to add default value for date field through fluent API entity framework in .net core. my code is below :-
builder.Property(e => e.DOB)
.HasColumnType("date")
.HasDefaultValueSql("getdate()");
but this not working.
How to add default value for date field through fluent API entity framework in .net core
Actually, defualt date value can be generated in various ways. In other words, entity framework core providers usually don't set up value generation automatically for date/time columns - you have to configure this yourself.
In addition, based on your scenario, you could do as following:
builder.Property(e => e.DOB).HasDefaultValueSql("getdate()");
Note: For more details, you could have a look at this official document.