0

the existing code is:

....
domainModel.EntityDataContext.Attach(entry);
....
domainModel.EntityDataContext.Commit();

I'm not allowed to edit the attach method and commit as it will create huge regression issues, but I'm wondering how can I obtain entry's id ?

jamesdeath123
  • 4,268
  • 11
  • 52
  • 93
  • 4
    Does the Id not automatically update on the entity after it is committed? See: http://stackoverflow.com/a/3290209/1341477 and http://stackoverflow.com/a/5212787/1341477 – Dave Williams Jun 28 '13 at 14:03
  • This is not doable unless you are manually setting the id in your database.If you don't insert the key's value hasn't been generated yet. – Alex Jun 28 '13 at 14:09
  • You will need something like this: http://stackoverflow.com/questions/15893141/how-do-you-get-a-dbentityentry-entitykey-object-with-unknown-name – nemesv Jun 28 '13 at 14:11
  • possible duplicate of [How can I get Id of inserted entity in Entity framework](http://stackoverflow.com/questions/5212751/how-can-i-get-id-of-inserted-entity-in-entity-framework) – cadrell0 Jun 28 '13 at 14:13
  • @DaveWilliams the thing is I cannot change the commit codes, so I cannot use the SaveChange etc. .. – jamesdeath123 Jun 28 '13 at 18:39
  • If commit is not using SaveChanges then how is it saving data? If you really can't do anything to edit it then you may have to resort to fetching the data back from the database manually which seems a bit like a waste if using the framework. – Dave Williams Jul 01 '13 at 07:27

0 Answers0