当在数据库中用作主键时,有人曾测量过Sequential Guid与Standard Guid的性能吗?
有没有办法获得Sql Server 2005+ Sequential Guid生成器的功能,而无需插入记录来回读往返或调用本机win dll调用?我看到有人回答使用rpcrt4.dll,但我不确定是否可以从我的托管环境中进行生产.
编辑:使用@John Boker的答案我试图把它变成GuidComb生成器的更多,而不是依赖于最后生成的Guid而不是重新开始.对于种子,而不是从我使用的Guid.Empty开始
public SequentialGuid()
{
var tempGuid = Guid.NewGuid();
var bytes = tempGuid.ToByteArray();
var time = DateTime.Now;
bytes[3] = (byte) time.Year;
bytes[2] = (byte) time.Month;
bytes[1] = (byte) time.Day;
bytes[0] = (byte) time.Hour;
bytes[5] = (byte) time.Minute;
bytes[4] = (byte) time.Second;
CurrentGuid = new Guid(bytes);
}
Run Code Online (Sandbox Code Playgroud)
我根据评论做了这个
// 3 - the least significant byte in Guid ByteArray
[for SQL Server ORDER BY clause]
// 10 - the most significant byte in Guid ByteArray …Run Code Online (Sandbox Code Playgroud)