gpt4 book ai didi

c# - 首先使用 EF 代码将 datetime2 数据类型转换为 datetime 数据类型错误?

转载 作者:可可西里 更新时间:2023-11-01 08:07:07 24 4
gpt4 key购买 nike

我首先在我的 asp.net mvc 应用程序中使用 EF 代码。这是我的代码:

Request.RequestDate = DateTime.Now;

RequestDate 的类型是我数据库中的日期时间。这是我使用上述代码时发生的错误!:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

请帮帮我。谢谢。

最佳答案

编辑:

How to fix the datetime2 out-of-range conversion error using DbContext and SetInitializer?

问题是您尝试保存的值不适合 SQL 日期时间列。此处给出的答案将阻止转换失败。

或者在您的数据库中将列更改为 datetime2 类型。我不完全知道为什么他们首先编码是生成日期时间列而不是 datetime2

这是一个在 SQL 中将 Datetime 列显式映射到 datetime2 的示例

Using DateTime properties in Code-First Entity Framework and SQL Server

关于c# - 首先使用 EF 代码将 datetime2 数据类型转换为 datetime 数据类型错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10585214/

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