EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
2015-03-28 12:15
633 查看
在SQL server 中,有两种日期时间类型:1、DateTime 它的范围是 1753-1-1 至 9999-12-312、DateTime2 它的满园是 0001-01-01 至 9999-12-31EF实体框架给一个DateTime字段加载一个默认值是 {01/01/0001 00:00:00},它已经在SQL日期类型的范围之外了。所以,如果要让他正常工作,我们需要告诉EF框架不需要创建一个默认的日期时间值。我们可以在模型类型上加一个可空类型,表示它的值是可以为空的。
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
[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
相关文章推荐
- [entity framework ] The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
- conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
- The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. 错误的原因及解决方案
- The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- All-In-One Code Framework(AIO): 如何使用C#编写进程外的COM组件 (How to write an out-of-proc COM server in C#)
- (C#) A demo on how to auto fill out the "account" value in log in web page in "WebBrowser" control.
- sql常犯错误之不正确的谓词运算顺序Conversion failed when converting the varchar value 'abc' to data type int
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- The method below converts an array of objects to a DataTable object in C#.
- ERROR: The version of SQL Server in use does not support datatype 'datetime2'.
- [Javascript] A function works like 'print_r()' in PHP to print out the details of an object for JS debugging
- The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List
- ADO.NET Entity Framework: The version of SQL Server in use does not support datatype 'datetime2'
- Fast ways in R to get the first row of a data frame grouped by an identifier
- In a bunch of number to find out the biggest minimum value
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- 海洋工作室——网站建设专家:The version of SQL Server in use does not support datatype datetime2 and the Entity Framework.
- In C# how to find the mime type of a file
- The version of SQL Server in use does not support datatype 'datetime2'.