2 Star 3 Fork 1

wangzhanbo/cms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DB.FunctionNewGuid.cs 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
wangzhanbo 提交于 7年前 . add new code
using System;
using System.Data.SqlTypes;
public class FunctionNewGuid
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlGuid NewSequentialGuid()
{
const int RPC_S_OK = 0;
Guid guid;
int result = UuidCreateSequential(out guid);
if (result != RPC_S_OK)
{
throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
}
else
{
byte[] guidBytes = guid.ToByteArray();
Array.Reverse(guidBytes, 0, 4);
Array.Reverse(guidBytes, 4, 2);
Array.Reverse(guidBytes, 6, 2);
long timestamp = DateTime.UtcNow.Ticks / 10000L;
byte[] timestampBytes = BitConverter.GetBytes(timestamp);
if (BitConverter.IsLittleEndian)
{
Array.Reverse(timestampBytes);
}
Buffer.BlockCopy(timestampBytes, 2, guidBytes, 10, 6);
return new SqlGuid(guidBytes);
}
}
[System.Runtime.InteropServices.DllImport("rpcrt4.dll", SetLastError = true)]
private static extern int UuidCreateSequential(out Guid guid);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/wangzhanbo/cms.git
git@gitee.com:wangzhanbo/cms.git
wangzhanbo
cms
cms
master

搜索帮助