entity framework - retrieve Ids created by savechanges -


apologies asking related question yesterday, after sleep i've simplified question.

in example below,i loop through objectquery sourcetable , add rows positions table. after adding new rows , saving changes, primary keys (integer identity column) created.

foreach (var row in sourcetable)         {             var newpos = new positions()                 {                     field1 = row.field,                     field2 = row.field2,                     field3 = row.field3                  };          }      entities.savechanges 

in ef 3.5 possible access list of primary keys added above process? similar can done using output statement in t-sql.

sure - need hang on list of entities you're save, , inspect them after they've been saved:

list<positions> _newitems = new list<positions>();  foreach (var row in sourcetable) {     var newpos = new positions()     {         field1 = row.field,         field2 = row.field2,         field3 = row.field3      };      _newitems.add(newpos);  }  entities.savechanges();  foreach(positions p in _newitems) {     console.writeline("id new item is: {0}", p.id); } 

after items have been saved, field representing int identity field should updated automagically, ef, without doing more. inspect field!


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -