天道酬勤,学无止境

datetime2

Datetime2 conversion in EF4

well, after having spent endless time googling for an answer , i have to add another question in this matter... i have a table with 2 datetime fields, generated by EF4 EDMX designer in VS 2010. the generated fields in SQL 2008 are datetime and not datetime2. looking at the edmx markup, the fields are of type datetime2. the insert is failing with the known conversion issue datetime2 / datetime.... i have manually changed the fields to datetime2 on the sql table. still no luck. i am probably missing something here but can't figure out what the heck is going on. i even tried regenerating the db

2021-06-15 02:12:36    分类:问答    entity-framework-4   designer   edmx   datetime2

Hibernate MSSQL datetime2映射(Hibernate MSSQL datetime2 mapping)

问题 我有一个存储过程,该过程返回数据库中数据类型为datetime2以及Java文件中Date为数据类型的列。 当我尝试在从数据库获取的时间上调用getTime()时。 它返回的19994321211毫秒等于IST 2015年5月4日星期一。理想情况下,它应返回2015-05-04 15:21:52的毫秒,因为这是直接执行过程时数据库中显示的时间。 由于我是Hibernate的新手,所以我无法理解问题是否与hibernate映射有关,或者我是否错过了其他事情。 <hibernate-mapping> <sql-query name="getMLC"> <return-scalar column="mlcid" type="int" /> <return-scalar column="completionTime" type="date" /> { call lsc.MLC_Get(:ABC, :XYZ, :ErrorCode)} </sql-query> </hibernate-mapping> class Mlc implements java.io.Serializable { private Integer mlcid; private Date completionTime; // getter and setter } 回答1 尝试像这样注册一个新的驱动程序:

2021-06-01 12:59:58    分类:技术分享    java   sql-server   database   hibernate   datetime2

SQL ignore nanoseconds when comparing datetime2

I have 2 tables with a datetime2 field each. One of the tables has stored nanoseconds as well, while the other one only stores up to milliseconds (there is no way to change this data). Now I want to compare the 2 tables and check if the datetime2 values match, but I have to ignore the nanoseconds for this. Sample data: Table1 Table2 2018-01-24 10:51:23.9976180 2018-01-24 10:51:23.9970000 2018-01-24 10:51:23.9976180 2018-01-24 10:51:23.9970000 2018-01-24 11:08:23.2578500 2018-01-24 11:08:23.2570000 my query currently looks like this: select t1.* from Table1 t1, Table12 t2 where t1.tradeDateTime

2021-05-08 12:37:03    分类:问答    sql   sql-server   datetime2

使用SQL Server 2008和SQL Server 2005以及日期时间(Using SQL Server 2008 and SQL Server 2005 and date time)

问题 我已经针对2008数据库建立了一个实体框架模型。 对于2008数据库,一切正常。 当我尝试在2005数据库上更新实体时,出现此错误。 The version of SQL Server in use does not support datatype 'datetime2 建立数据库时,我没有使用任何2008功能。 我在代码中找不到对datetime2的任何引用。 并且,是的,该列在数据库中定义为“ datetime”。 回答1 一个快速的谷歌指出我看起来像解决方案。 在文件编辑器中打开EDMX(或在Visual Studio中“用...打开”,然后选择XML编辑器)。 在顶部,您将找到存储模型,它具有ProviderManifestToken属性。 该值应为2008。将其更改为2005,重新编译,一切正常。 注意:每次从数据库更新模型时,都必须执行此操作。 回答2 快速浏览线: <Schema Namespace="Foobar.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" > 回答3 这非常令人沮丧,我很惊讶MS决定不这样做,因此您可以针对给定的SQL版本。 为了确保我们的目标是2005年,我编写了一个简单的控制台应用程序

2021-05-08 11:09:45    分类:技术分享    sql-server-2005   entity-framework   sql-server-2008   datetime   datetime2

How is SQL Server's timestamp2 supposed to work in JDBC?

I'm having some trouble trying to use timestamp2 instead of Timestamp in SQL Server 2008. Apparently, rs.getTimestamp has very different behavior between timestamp and timestamp2. However, I can't find any documentation stating that there should be a difference, or that I should be using something different. I wonder whether I'm just doing something wrong. Environment: Tried on both SQL Express 2008 (10.0) and SQL Server 2008 R2 (10.5). sqljdbc4.jar version 3.0, size of 537,303 bytes, CRC-32=a0aa1e25, MD5=402130141d5f2cee727f4371e2e8fd8a. Java 1.6 Here is a unit test demonstrating the problem

2021-05-06 11:57:12    分类:问答    java   sql-server-2008   datetime2   sqljdbc

Hibernate MSSQL datetime2 mapping

I have a stored procedure which is returning a column having datatype as datetime2 in database and Date in Java file. When I am trying to call getTime() on that obtained time from database. It's returning 19994321211 millisecond which is equivalent to Mon May 04 00:00:00 IST 2015. ideally it should return milliseconds of 2015-05-04 15:21:52 as this is the time shown in database when procedure is executed directly. As I am new to Hibernate , I am unable to understand if the issue is related to hibernate mapping or something else I am missing out. <hibernate-mapping> <sql-query name="getMLC">

2021-05-03 10:09:30    分类:问答    java   sql-server   database   hibernate   datetime2

在将可为空的日期时间插入数据库时​​,为什么EF5代码首先使用datetime2?(Why does EF5 code first use datetime2 when inserting a nullable datetime into the database?)

问题 我正在将Cart对象保存到具有可空日期时间的数据库中。 这是我得到的错误: datetime2数据类型到datetime数据类型的转换导致超出范围的值。 有很多stackoverflow帖子记录了针对此问题的修复程序。 但是,当代码首次创建数据库时,它将创建该字段作为DateTime(允许为null)。 但是由于某种原因,代码首先尝试使用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 {

2021-04-24 12:05:14    分类:技术分享    entity-framework   datetime   ef-code-first   datetime2

Using SQL Server 2008 and SQL Server 2005 and date time

I've built a entity framework model against a 2008 database. All works ok against the 2008 database. When I try to update the entity on a 2005 database I get this error. The version of SQL Server in use does not support datatype 'datetime2 I specifically did not use any 2008 features when I built the database. I can't find any reference to datetime2 in the code. And, yes the column is defined as "datetime" in the database.

2021-04-12 01:02:31    分类:问答    sql-server-2005   entity-framework   sql-server-2008   datetime   datetime2

Why does EF5 code first use datetime2 when inserting a nullable datetime into the database?

I am saving a Cart object to the database that has a nullable datetime. This is the error I get: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. There are quite a few stackoverflow posts documenting fixes to this problem. However, when code first is creating the database it will create the field as a DateTime (allow nulls). But for some reason, code first tries to insert using a DateTime2 field. I am wondering why EF creates the field one way, but inserts using a different type for the same field. This is the domain object: using System; using

2021-04-05 02:47:30    分类:问答    entity-framework   datetime   ef-code-first   datetime2

SQL Server中的DateTime2 vs DateTime(DateTime2 vs DateTime in SQL Server)

问题 哪一个: 约会时间 datetime2 SQL Server 2008+中存储日期和时间的推荐方法是什么? 我知道精度(可能还有存储空间)上的差异,但是暂时忽略这些差异,是否有关于何时使用什么的最佳实践文档,或者也许我们应该仅使用datetime2 ? 回答1 有关datetime的MSDN文档建议使用datetime2。 这是他们的建议: 将time , date , datetime2和datetimeoffset数据类型用于新工作。 这些类型符合SQL标准。 它们更便携。 time , datetime2和datetimeoffset提供更高的秒精度。 datetimeoffset为全局部署的应用程序提供时区支持。 datetime2具有更大的日期范围,更大的默认小数精度和可选的用户指定精度。 另外,根据用户指定的精度,它可能会使用较少的存储空间。 回答2 DATETIME2的日期范围是“ 0001/01/01”到“ 9999 / 12/31”,而DATETIME类型仅支持1753-9999年。 另外,如果需要, DATETIME2可以在时间上更精确; DATETIME限制为3 1/3毫秒,而DATETIME2可以精确到100ns。 这两种类型都映射到.NET中的System.DateTime那里没有区别。 如果您有选择,我建议您尽可能使用DATETIME2 。

2021-03-26 12:41:21    分类:技术分享    sql   sql-server   tsql   datetime   datetime2