EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
在SQL server 中,有两种日期时间类型:
1、DateTime 它的范围是 1753-1-1 至 9999-12-31
2、DateTime2 它的满园是 0001-01-01 至 9999-12-31
EF实体框架给一个DateTime字段加载一个默认值是 {01/01/0001 00:00:00},它已经在SQL日期类型的范围之外了。所以,如果要让他正常工作,我们需要告诉EF框架不需要创建一个默认的日期时间值。我们可以在模型类型上加一个可空类型,表示它的值是可以为空的。
[Display(Name = "LastLoggedIn")]
public DateTime? LastLoggedIn { get; set; }
日期时间对象创建:
BirthDate = new DateTime(1990, 6, 1),
DateTime.Parse("2010/10/1");
转换日期:
分为长日期,长时间和短日期和短时间。
BirthDate.ToString("D") 转换为本地化的时间,如1990年6月1日。
Birthdate.ToLongDateString()
BirthDate.ToString("d") 转换为简写的时间。如1990/6/1.
BithDate.ToShortDateString();
BithDate.ToString("yyyy-MM-dd") 1990-06-01
EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间的更多相关文章
- The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data ...
- The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. 错误的原因及解决方案
异常描述: 数据访问用EF,在数据库中用getdate()设置的默认值,程序中没有赋值. 出现异常. 此错误在百度上在我写此文之前没有多少解决方案,谷歌之等到以下两个有用的页: http://stac ...
- 3.EF 6.0 Code-First实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-entity-framework-5-0-code- ...
- EF 5.0 帮助类
EF 5.0 帮助类 加入命名空间: using System; using System.Data; using System.Data.Entity; using System.Data.Enti ...
- EF 5.0 帮助类 增删改查
原文地址:http://www.cnblogs.com/luomingui/p/3362813.html EF 5.0 帮助类 加入命名空间: using System; using System.D ...
- EF 6.0
最近又开始研究EF框架了 哎 搞的东西太杂了 网上的参考了一篇博客 但是他是基于EF 4.0之前做的 所以自己基于他的博客来构造EF 6.0的使用基础 命名空间不同: 旧版本:using System ...
- ASP。netcore,Angular2 CRUD动画使用模板包,WEB API和EF 1.0.1
下载Angular2ASPCORE.zip - 1 MB 介绍 在本文中,让我们看看如何创建一个ASP.NET Core CRUD web应用程序与Angular2动画使用模板包,web API和EF ...
- EF Core3.0+ 通过拦截器实现读写分离与SQL日志记录
前言 本文主要是讲解EF Core3.0+ 通过拦截器实现读写分离与SQL日志记录 注意拦截器只有EF Core3.0+ 支持,2.1请考虑上下文工厂的形式实现. 说点题外话.. 一晃又大半年没更新技 ...
- Failed to register: Error: fabric-ca request register failed with errors [[{"code":0,"message":"No identity type provided. Please provide identity type"}]]解决方案
I try to run sample application as stated here : http://hyperledger-fabric.readthedocs.io/en/release ...
随机推荐
- hdu1059(背包dp二进制优化)
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 2016 Multi-University Training Contest 5 solutions BY ZSTU
ATM Mechine E(i,j):存款的范围是[0,i],还可以被警告j次的期望值. E(i,j) = \(max_{k=1}^{i}{\frac{i-k+1}{i+1} * E(i-k,j)+\ ...
- 9.6——string类型
string: getline(is,s):从输入流is读入到字符串s中 s1+s2:将两个字符串连接起来 构造string一些方法: 1)string s(cp,n):将s初始化为cp所指的n个字符 ...
- Spring MVC中 log4j日志文件配置相对路径
log4j和web.xml配置webAppRootKey 的问题 1 在web.xml配置 <context-param> <param-name>webAppRootKey ...
- VB程序逆向反汇编常见的函数(修改版)
VB程序逆向常用的函数 1) 数据类型转换: a) __vbaI2Str 将一个字符串转为8 位(1个字节)的数值形式(范围在 0 至 255 之间) 或2 个字节的数值形式(范围在 -32,7 ...
- centos mysql错误信息处理
mysql_secure_installation 提示错误:Enter current password for root (enter for none):ERROR 1045 (28000): ...
- POJ 3488 & HDU 1915 Arne Saknussemm(模拟)
题目链接: POJ:http://poj.org/problem? id=3488 HDU:pid=1915">http://acm.hdu.edu.cn/showproblem.ph ...
- JS应用之禁止抓屏、复制、打印
JS应用之禁止抓屏.复制.打印项目需要禁止抓屏.复制.打印的要求,复制.打印做起来可能顺手一点网上各种各样的脚本俯首皆是.但抓屏怎么禁止?PrintScreen是一个特殊的键,它是没有keyCode的 ...
- SPOJ QTREE6 lct
题目链接 岛娘出的题.还是比較easy的 #include <iostream> #include <fstream> #include <string> #inc ...
- Unable to find a team with the given Team ID或者Failed to code sign的问题解决
Unable to find a team with the given Team ID或者Failed to code sign的问题解决 1:问题描述(注:这种情况一般是下载并打开别人项目时) F ...