开发者

Unique IDs over database globally using Entity Framework

I want to have unique object ids o开发者_JS百科ver 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

http://msdn.microsoft.com/en-us/library/dd283139.aspx


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜