• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

repopulate primary key after linq to sql delete

Hi There experts,
I'm new to linq. I've got a delete function working in my windows form app using c# linq to sql to remove a row from my database. It works fine, I was just wondering if there was an easy way to reorder the primary key of the table the record was deleted from after the delete. by which i mean, currently if i have 3 records and i delete record number 2 then i will be left with a record with an id of 1 and a record with an id of 3. Is there a way to make the id's re-order themselves so in the above scenario when record 2 was deleted record 3 would now have an id of 2?
0
Jazzua
Asked:
Jazzua
1 Solution
 
naspinskiCommented:
This has nothing to do with Linq really, and resides more in SQL.

Since your 'id' is a primary key, it is made automatically, and will *never* increment backwards.  Also, it can not be changes unless you take away the PRIMARY KEY and IDENTITY properties that you assigned to it, change the number, then re-assign those properties to the column - BAD IDEA!

I don't really see the application of this as you could always  programmatically generate the number in the sequence if you needed to.

But, what I would recommend if you *really* think you need this is to make another field as a psuedo-id that is a simple INT and use that one to keep your order.
0
 
JazzuaAuthor Commented:
cheers :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now