Identity (autoincrement) key and unit of work commit #220
-
Hi, This is ok if the Id is generated by the application (as in your case), but how to handle it in the case it's generated database side (identity keys). Probably the command should call the unit of work commit itself. Any thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, @martinobordin.
You can read more in Entity Identity vs Database Primary Key by Vladimir Khorikov. But of corse these concepts have two important requirements in common: they have to be immutable and globally unique. So it's often when entity identity is used as primary key. And Vaughn Vernon writes:
Returning to your question I think it's good separation of concerns to use decorator to manage database transaction. So to be able to return entity Id from a command handler Id generation must be a part of entities construction. So we can:
|
Beta Was this translation helpful? Give feedback.
Hi, @martinobordin.
First of all I would like to emphasise that following concepts are essentially independent:
You can read more in Entity Id…