Use sequential guids in c#(daniel.wertheim.se)

submitted by sedanwersedanwer(216) 1 year, 7 months ago

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

6 comments |category: |Views: 28

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by sdormansdorman(1415) 1 year, 7 months ago 0

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.

Reply

posted by sedanwersedanwer(216) replied to sdormansdorman(1415), 1 year, 7 months ago 0

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....

Reply

posted by sdormansdorman(1415) replied to sedanwersedanwer(216), 1 year, 7 months ago 0

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.

Reply

posted by sedanwersedanwer(216) replied to sdormansdorman(1415), 1 year, 7 months ago 0

You mean the unmanaged calls?

Reply

posted by sedanwersedanwer(216) replied to sdormansdorman(1415), 1 year, 7 months ago 0

And by the way do you really need sync in the application? The guids still uses time, doesn't they?

Reply

posted by sdormansdorman(1415) replied to sedanwersedanwer(216), 1 year, 7 months ago 0

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.

Reply

information Login or create an account to comment on this story