且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

T-Sql 中的时间戳在 C# 中是什么意思?

更新时间:2023-02-06 13:58:24

Sql Server 时间戳数据类型名称混淆.把它想象成一个版本号真的更好—任何地方都没有日期/时间信息.事实上,从 Sql Server 2008 开始,该类型已重命名为rowversion".

The name of the Sql Server timestamp data type is confusing. It's really better to think of it more like a version number — there's no date/time information in there anywhere. In fact, as of Sql Server 2008 the type was renamed to "rowversion".

大多数情况下,您希望在 Sql Server 中输入 datetime 类型,它可以轻松映射到 C# 中的 DateTime,或者可能是 datetime2 如果您有支持它的 Sql Server 版本.关于时间戳类型的文档在这里:
http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

Most of the time you want the datetime type in Sql Server instead, which maps easily to DateTime in C#, or perhaps datetime2 if you have a version so Sql Server that supports it. Documentation on the timestamp type is here:
http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

如果你真的必须按原样映射那个时间戳列,最接近的匹配可能是普通的旧 long(或者可能是 ulong),但我不知道 sql server 如何处理字节排序或 big/little endien-ness vs C#.

If you really must map that timestamp column as-is, the closest match is probably plain old long (or maybe ulong), but I have no idea how sql server handles byte ordering or big/little endien-ness vs C#.