首先我是EF核心代码中的新手,我想成为datetime形式的变量,但要使用Datetime2。我该如何解决?
这是EF核心,代码优先方法和sql server 2017
public class MB_Message
{
[Key]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int MessageID { get; set; }
public DateTime? expireDateTime { get; set; }
public string TypeName { get; set; }
public bool IsForceLastSend { get; set; }
public DateTime MessageDateTime { get; set; }
public bool ReadOnce { get; set; }
public string ExeCode { get; set; }
[ForeignKey("MB_Queue")]
public int QueueCode { get; set; }
public int? UserID { get; set; }
[ForeignKey("MB_MessageBody")]
public int BodyID { get; set; }
public bool Enable { get; set; }
}
答案 0 :(得分:0)
在您的dbcontext的OnModelCreating方法中,添加以下内容:
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<MB_Message>()
.Property(x=> x.MessageDateTime )
.HasColumnType("datetime");
}