Generate non-identity primary key
        Posted  
        
            by MikeWyatt
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by MikeWyatt
        
        
        
        Published on 2010-04-16T15:00:11Z
        Indexed on 
            2010/04/16
            15:03 UTC
        
        
        Read the original article
        Hit count: 368
        
linq-to-sql
|primary-key
My workplace doesn't use identity columns or GUIDs for primary keys. Instead, we retrieve "next IDs" from a table as needed, and increment the value for each insert.
Unfortunatly for me, LINQ-TO-SQL appears to be optimized around using identity columns. So I need to query and update the "NextId" table whenever I perform an insert. For simplicity, I do this immediately creating the new object.
Since all operations between creation of the data context and the call to SubmitChanges are part of one transaction, do I need to create a separate data context for retrieving next IDs? Each time I need an ID, I need to query and update a table inside a transaction to prevent multiple apps from grabbing the same value.
Is a separate data context the only way, or is there something better I could try?
© Stack Overflow or respective owner