tags:

views:

36

answers:

3

hi there

I have an entity and it seems like using DateTime as the Id would be a good suit, however I there is this strange feeling that that it might be a terrible idea ( tho i cant come up with any logical reason as to why),

This is an immutable object ( ie once the value is recorded it shouldn't really change ) So DateTime as id field in NHibernate yay or Nay? I would appreciate your comments on this

+1  A: 

Very bad idea. What if you have duplicates? You have no way of guaranteeing the uniqueness of the field. You probably won't get two objects created at the same time, but it's not guaranteed. With an auto-incrementing or GUID, however, you do know that the database will take care of keeping its keys consistent.

Joe
+1  A: 

Bad idea. Never, ever have unique id to have some meaning, cause meaning can change, some other constraint on meaning can also change, and id has to be just that, an id.

If you have to, you can put unique index on datetime field and use it in queries, but keep id as guid or autinc.

Dev er dev
+1  A: 

Very Bad Idea. It might not be unique, it has many meanings (+/- GMT ) ect. Use Identity column instead and store datetime in a separate column.

Dani