What is the preferred Entity Framework identity generating approach?

.net c# entity-framework identity

Question

How to use StoreGeneratedPattern in the most effective manner is what interests me.

I used to let the database produce my ID in the past, but I was curious whether there are any benefits to setting

StoreGeneratedPattern = None 

in place of

StoreGeneratedPattern = Identity

Even when I set it to Calculated, I'm not sure what occurs.

Have any suggestions? Is there a decent article on this anywhere since MSDN doesn't really explain it. In my schema, I generally use ints and a few GUIDs.

1
10
12/20/2011 7:14:58 PM

Accepted Answer

Verify my blog entry aboutStoreGeneratedPattern It clarifies some variations betweenIdentity and Computed When usingStoreGeneratedPattern The appropriate response for ID (PK) isNone if the program assigns an ID orIdentity if ID in DB is assigned.Computed option is "invalid" since ID is not the case here; instead, this option is utilized when value is modified throughout each entity's persistence (including during updates).

The distinction betweenIdentity and Computed is the action of the SQL command. if a propertyIdentity After Insert, EF will choose the value and send it back to your application. if a propertyComputed After Insert and Update, EF will choose the value and return it to your application.

Edit:

StoreGeneratedPattern.Identity is unrelated to database identity. You may establish ID using a different technique (such as the default value for a guid or trigger) and you don't even need to store identity in the database, but you still needStoreGeneratedPattern.Identity in order to provide value to your application.

when you start utilizingIdentity or Computed Every Insert or Update will always be followed by a Select for columns created by the database. Without it, it cannot function. Since these commands only need one roundtrip to the database, the performance effect is minimal.

20
11/29/2018 6:38:56 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow