I have some tables with several fields of type datetime, and for all of them I need to create a validation in OnModelCreating () for this type, that is, I need to set .HasColumnType("datetime");
, my doubts are;
Is there a more practical way to define this in some way as a default?
Something like;
modelBuilder.Entity<Usuarios>()
.Property(so => so.Contains("dt)) // contem dt inicia dos campos datetime
.HasColumnType("datetime");
The idea and not having to repeat this many times as I had to do below.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Usuarios>()
.Property(so => so.dtAdmissao)
.HasColumnName("dtAdmissao")
.HasColumnType("datetime");
modelBuilder.Entity<Usuarios>()
.Property(so => so.dtInclusao)
.HasColumnName("dtInclusao")
.HasColumnType("datetime");
modelBuilder.Entity<Usuarios>()
.Property(so => so.dtNascimento)
.HasColumnName("dtNascimento")
.HasColumnType("datetime");
base.OnModelCreating(modelBuilder);
}