Hi. I want to have unique object ids over whole database. Is there any built-in feature in EF? Or may be there are some practices/patterns?
thanks in advance.
Hi. I want to have unique object ids over whole database. Is there any built-in feature in EF? Or may be there are some practices/patterns?
thanks in advance.
If you are using SQL Server as the backend, you could look into using a UNIQUEIDENTIFIER column rather than an IDENTITY column, which means you can use GUIDs for your IDs across the entire database.
See "GUID Property Values" in the following MSDN article for EF4
1) Create table to store last id (int, bigint) (identifier domain)
2) Add stored procedure to retrieve the next id (int, bigint).
3) You may implement Custom Data Class EntityObject and ComplexObject (or maybe assign to every entity manualy in code)
4) Use this id in your custom class as primary key
--
If you using GUID...EF(4) has build-in feature to do this. But GUID as primary key with CLUSTERED INDEX is bad solution for the many insertion of course.