New Posts New Posts RSS Feed: best way for getting real ID
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

best way for getting real ID

 Post Reply Post Reply
Author
erturkcevik View Drop Down
Groupie
Groupie


Joined: 14-Jun-2007
Location: Turkey
Posts: 40
Post Options Post Options   Quote erturkcevik Quote  Post ReplyReply Direct Link To This Post Topic: best way for getting real ID
    Posted: 04-Jun-2008 at 7:13am
Hi;
How can I getting the real primary key value after SaveChanges. I’m using custom ID generater.
Please give me some example code.
This following code running properly, but I'm not sure is the best way.
 
private EntityList<HT_HESAPPLANI> mHPDetay ;
private int HPID;
 
aHESAPPLANI = HT_HESAPPLANI.Create(mPersMgr, "", "");
mHPDetay = new EntityList<HT_HESAPPLANI>();
mHPDetay.Add(aHESAPPLANI);
mHPDetayBS.DataSource = mHPDetay;
 
mPersMgr.SaveChanges(mHPDetay);
HPID = mHPDetay[0].ROWID;
PrimaryKey HpPK = new PrimaryKey(typeof(HT_VHESAPPLANI), HPID);
HT_VHESAPPLANI pEntityHP = (HT_VHESAPPLANI)mPersMgr.GetEntity(HpPK, QueryStrategy.DataSourceOnly);
 
 
Best Regards
 
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 04-Jun-2008 at 8:54am
Erturk.
 
The default behavior of SaveChanges is to return the updated entity to the client cache, so there is no need to query the database.  Just access your updated entit y.  It's primary Id will be updated.  However, this will not work if you use the ExcludeFromPostSaveRefetch SaveOption.
 
If you want to convert your temporary id to a real permanent id before you do the save, use the ForceIdFixup method of the PersistenceManager,
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down