【发布时间】:2020-12-03 05:05:11
【问题描述】:
我对编码非常陌生,遇到了一个问题。我正在做一个 ASP.NET Core 3.1 MVC 应用程序。我正在尝试使用日期列创建模型,但没有任何成功。我使用的代码如下所示。
我的想法是必须有一种方法可以在 SQL 中存储日期,但无济于事。非常感谢任何对话或 cmet。
错误发生在这一行
public Date CreationDate { get; set; }
它不会接受 Date 作为数据类型。
问候史蒂夫
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace SalesAccount.Models
{
public class Contract
{
[Key]
public int Id { get; set; }
[Required]
**public Date CreationDate { get; set; }**
[Required]
public char ContractNumber { get; set; }
}
}
【问题讨论】:
-
.NET / C# NOT 有一个名为
Date的数据类型 - 您始终需要使用DateTime(或DateTimeOffset,如果时区信息相关)
标签: sql model-view-controller types