Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How can I create an auto id number using linq?
Posted
Updated 6-Dec-10 5:14am
v3
Comments
Dalek Dave 6-Dec-10 4:10am    
Minor Edit for Readability.
m@dhu 6-Dec-10 4:26am    
Whats in there to edit DD?

You don't. AutoId numbers are generated by the database engine upon record creation.
 
Share this answer
 
How about this

Generate a number which equals to clock ticks. The ticks will be always unique.This will gurantee you generate an auto Id every time, though not starting at 1.

Now the issue is when you scale out and have multiple servers what do you do?
In such a case you should assign each server a number between 1000 and 9999 and prepend it to your tick

Now what if one each server you have multiple app's
In this case assign a similar number to each app and prepend it between server id and tick

So the auto gen number will be ServerId AppId Tick

A point to Dave. Linq may be used against an OO DB and not always a RDBMS.

Further ANSI standards say that you cant have identity mantained by DB.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900