Print Page | Close Window

best way for getting real ID

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=824
Printed Date: 19-Apr-2025 at 5:03am


Topic: best way for getting real ID
Posted By: erturkcevik
Subject: best way for getting real ID
Date 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
 



Replies:
Posted By: davidklitzke
Date 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,



Print Page | Close Window