Use sequential guids in c#

added by sedanwer
10/14/2010 1:45:36 PM

-1 Kicks, 142 Views

Shows you how you could use sequential guids in C# by letting Sql-server generate them.


10/14/2010 9:49:53 PM
Don't see how this approach would be all that useful. Having the database generate the sequential GUIDs is fine and keeping them in a queue on the .NET side is ok. The problems you're going to hit are protecting access to the queue, ensuring that an entry isn't reused, knowing how many GUIDs to create initially and each time the queue becomes emtpy, not to mention taking a database hit each time you need to refill the queue.

10/18/2010 3:16:19 AM
As I said. I'm not saying you shoul. I'm saying you could. Of course it leads to having to move the sync to your application....

10/18/2010 12:31:42 PM
Yes, but there are other ways to do this where you can create a sequential GUID locally on the application side which uses the same logic as used by SQL Server.

10/18/2010 2:20:36 PM
You mean the unmanaged calls?

10/18/2010 2:21:44 PM
And by the way do you really need sync in the application? The guids still uses time, doesn't they?

10/18/2010 8:20:37 PM
If I understand what you're asking, you can create a complete C# class which mimics everything about a normal Guid but changes the implementation so that it uses the same logic used by SQL Server to generate the actual Guid values.

Needing sync would largely depend on the application, but if you use SQL Server to create a pool of sequential Guids that are queued by the application, every so often you will need to go back to that pool and generate a new group.