Using DateTime properties in Code-First Entity Framework and SQL Server
You can specify the type in Fluent API: modelBuilder.Entity<Book>() .Property(f => f.DateTimeAdded) .HasColumnType(“datetime2”); This creates a datetime2(7) column in the database. If you want to finetune the precision you can use: modelBuilder.Entity<Book>() .Property(f => f.DateTimeAdded) .HasColumnType(“datetime2”) .HasPrecision(0); … for a datetime2(0) column in the DB. However, the code you have shown in your question works … Read more