I'm creating an entity diagram and I have a question about the StoreGeneratedPattern property on the Id's. I have both Identity and Computed options, and I'm not sure when to use each one. I guess that I should use Identity when it is generated by the entity and use Computed when is a foreign key, since is generated by another identity. Am I right or is the other way around ? Thanks!
Add a comment
|
1 Answer
If you would just simply look at the official MSDN documentation for this property, you would see:
Member name Description
-----------------------------------------------------------------------------
Computed A value is generated on both insert and update.
Identity A value is generated on insert and remains unchanged on update.
None A value indicating that it is not a server generated property.
So if you have a PK column that's an INT IDENTITY, then it's clear - use the Identity value.
The Computed value should be used for computed columns in your database tables, that are typically calculated on insert and re-calculated on update. This is NOT intended for foreign key columns! Those are just regular columns - do NOT set any StoreGeneratedPattern value for those!!