entity framework - Handle generation of non-identity primary key -


we have tables don't have identity primary key. costly change because of interoperability.

i'm thinking handling objectcontext's savingchanges event set values.

(pseudocode)

void savingchanges(context) {     foreach (var entity in context)     {         if (entity.hasidentity) continue;          entity.primarykey = getnextprimarykey(entity.type);     } } 

i can think of using separate connection accomplish this. , yes, getnextprimarykey otimized reduce number of roundtrips, guess suficient explain overall idea.

would work? should try different?

this depends upon logic within method getnextprimarykey.

if method executed in multiple threads have chances of same key being assigned multiple objects.

buti if getnextprimarykey advances key , returns new key, regardless of whether used or not, there no problem.

but if logic find out last used key , key + 1, in multithreaded situations or web applications, have conflicts.

best use sort of stored procedure , return new key sp, there not issue in case of parallel execution of getnextprimarykey.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -