EFCore 2.0 default all date fields to use datetime2

.net asp.net-core c# entity-framework entity-framework-core

Question

In EF6 i could use the following code so that all my dates use datetime2(0) as the column type

modelBuilder.Properties<DateTime>()
    .Configure(c => c
    .HasColumnType("datetime2")
    .HasPrecision(0));

How can i do this in EFCore??

1
3
6/6/2017 2:43:56 PM

Popular Answer

You need to install the Nuget Package: Microsoft.EntityFrameworkCore.SqlServer. After install, you can use HasColumnType("datetime") in your property. :)

4
2/18/2019 1:22:38 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow