gpt4 book ai didi

.net - SQL 'time' type in Entity Framework Code First

转载 作者:行者123 更新时间:2023-12-03 10:56:29 26 4
gpt4 key购买 nike

我正在尝试使用 Entity Framework Code First 在表中创建一个 'time(7)' 列。这是我的实体:

public class ShiftDetail
{
public long Id { get; set; }

[Required]
public int DayOfWeek { get; set; }

[Required]
[Column(TypeName="time")]
public DateTime StartTime { get; set; }

[Required]
[Column(TypeName = "time")]
public DateTime EndTime { get; set; }

public long ShiftId { get; set; }
public virtual Shift Shift { get; set; }
}

如您所见,我正在尝试将 StartTime 和 EndTime 列的数据库类型设置为“时间”,但出现此错误:

(112,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.DateTime[Nullable=False,DefaultValue=,Precision=]' of member 'StartTime' in type 'ShiftDetail' is not compatible with 'SqlServer.time[Nullable=False,DefaultValue=,Precision=7]' of member 'StartTime' in type 'CodeFirstDatabaseSchema.ShiftDetail'.



我也试过 TypeName="time(7)"但我得到了另一个错误:

(104,6) : error 0040: The Type time(7) is not qualified with a namespace or alias. Only primitive types can be used without qualification.



如何首先使用代码创建时间列? (最好没有流畅的 API)

提前致谢。

最佳答案

如果您想使用 Time输入您必须使用的数据库 TimeSpan在您的应用程序中以 24 小时为周期。 DateTime不是时间的表示。

关于.net - SQL 'time' type in Entity Framework Code First,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12186044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com