为什么1753?他们对1752有什么看法?我伟大伟大伟大曾伟大的曾祖父会非常生气.
我有一个包含5列的数据表,其中一行填充数据,然后通过事务保存到数据库.
保存时,会返回错误:
将datetime2数据类型转换为日期时间数据类型会导致超出范围的值
这意味着,正如所读,我的数据表有一种类型DateTime2
和我的数据库a DateTime
; 那是错的.
日期列设置为DateTime
如下所示:
new DataColumn("myDate", Type.GetType("System.DateTime"))
题
这可以在代码中解决,还是必须在数据库级别上进行更改?
我将Cart对象保存到具有可为空的日期时间的数据库.这是我得到的错误:
将datetime2数据类型转换为日期时间数据类型会导致超出范围的值.
有很多stackoverflow帖子记录了此问题的修复程序.但是,当代码首先创建数据库时,它将创建字段作为DateTime(允许空值).但由于某种原因,代码首先尝试使用DateTime2字段插入.
我想知道为什么EF以单向方式创建字段,但是为同一字段使用不同类型插入.
这是域对象:
using System;
using System.Collections.Generic;
namespace Core.Domain.Cart
{
public partial class Cart : BaseEntity, ILocalizedEntity
{
private ICollection<Catalog> _catalogs;
/// <summary>
/// Gets or sets the name
/// </summary>
public virtual string Name { get; set; }
/// <summary>
/// Gets or sets the zone identifier
/// </summary>
public virtual int ZoneId { get; set; }
/// <summary>
/// Gets or sets the brand identifier
/// </summary>
public virtual int BrandId { get; set; }
/// …
Run Code Online (Sandbox Code Playgroud)