2

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!

1 Answer 1

1

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!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.