Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以强制将所有DateTime属性建模为DateTime2?_C#_.net_Entity Framework_Ef Code First_Datetime2 - Fatal编程技术网

C# 是否可以强制将所有DateTime属性建模为DateTime2?

C# 是否可以强制将所有DateTime属性建模为DateTime2?,c#,.net,entity-framework,ef-code-first,datetime2,C#,.net,Entity Framework,Ef Code First,Datetime2,在Entity Framework 6 Code First中,是否有方法强制将所有DateTime属性建模为DateTime2 我知道我能做到 .HasColumnType("datetime2") 在每个单独的DateTime属性上,但我想知道是否有办法将其设置为所有DateTime属性的默认值。是的 在Entity Framework 6的Fluent API中,您可以使用以下一行更新所有DateTime属性: modelBuilder.Properties<DateTime>

在Entity Framework 6 Code First中,是否有方法强制将所有DateTime属性建模为DateTime2

我知道我能做到

.HasColumnType("datetime2")
在每个单独的
DateTime
属性上,但我想知道是否有办法将其设置为所有
DateTime
属性的默认值。

是的

在Entity Framework 6的Fluent API中,您可以使用以下一行更新所有
DateTime
属性:

modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2"));
modelBuilder.Properties().Configure(c=>c.HasColumnType(“datetime2”);