Return entity key after savechanges doesn't work
I have this piece of code
IMG_UPLOAD_FILES tObjUploadedFile = new 开发者_开发技巧IMG_UPLOAD_FILES();
tObjUploadedFile.UPLOAD_FILE_NAME = "testname.png";
tObjUploadedFile.SETTINGS_FOLDER_ID = 2;
dbHandler.IMG_UPLOAD_FILES.AddObject(tObjUploadedFile);
dbHandler.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
decimal tmpID= tObjUploadedFile.UPLOAD_FILE_ID;
the tmpID is still 0 and never return a key.
I have set StoreGeneratedPattern to Identity on the required field.
I'm using the latest ODB.NET from against the ORACLE database.
\T
The closest I can come to finding an answer is:
Because Oracle uses a Sequence + Trigger to make "Auto Ident" values, it seems like when the entity framework adds an object at saves it, the value return is still 0, because the trigger/sequence haven't updated it yet.
So the only way to come round this is to get the object again after you have save it.
\T
For me the fix was to manually (yes, manually!) go into the edmx, add the StoreGeneratedPattern="Identity"
attribute in the SSDL part, AND the annonation:StoreGeneratedPattern="Identity"
in the CSDL part.
It's not broken on the SQL side, however it is definitely broken on the Oracle side of things.
精彩评论