使用 ef 在数据库中使用没有时间的日期

Wou*_*ter 3 postgresql entity-framework asp.net-core

我应该使用什么类来保存带有 ef 和 asp.net 核心(使用数据库 postgres)的日期(没有时间)?DateTimeOffset 总是试图节省时间。

public class something
{
        [Column(TypeName="date")]
        [Required]
        public DateTimeOffset StartDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

tra*_*r0x 5

更改StartDateDateTime,而不是DateTimeOffSet

public DateTime StartDate { get; set; }
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用StartDate.Date( DateTime.Date)。