This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I'm currently investigating Lightspeed and have a couple of questions about KeyTable ID generation. I can see the advantages of this for the application layer but the application I'm writing will need to perform inserts in the database layer (through sprocs). I'm trying to find an easy or efficient way to retrieve a new ID from the keys table and use it in an SQL insert statement. I guess maybe a UDF but do you have any suggestions? Also, I've read this blog post and am a little confused: http://www.mindscape.co.nz/blog/index.php/2008/09/18/saving-large-numbers-of-entities-in-lightspeed/
When retrieving a block of IDs does Lightspeed cache them to use them across multiple requests and if so in what scope? (My DB is SQL Server 2005 and my project is an ASP.NET MVC web application). |
|
|
To manually get IDs from the KeyTable, issue a SELECT and UPDATE statement within the same transaction. You could of course wrap this in a stored procedure or UDF. The LightSpeed code simply SELECTs the current value of NextId and UPDATEs it to NextId + IdentityBlockSize. It then allocates IDs from the block on the client side. This is a more efficient approach than allocating IDs one at a time. Yes, LightSpeed caches blocks of IDs across multiple requests. The scope is the context: i.e. if you do multiple saves, even across multiple units of work, from the same LightSpeedContext, they will continue to use IDs from the already-allocated block, but if you create multiple LightSpeedContexts, each will get blocks allocated separately. You're right, the statement in the blog post is misleading -- sorry. |
|
|
Thanks Ivan that's great.
|
|