开发者

NHibernate dateTime as an ID Bad idea?

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 c开发者_如何学运维ant 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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜