Hello,
I have a problem getting the value of auto-incremented field of a new inserted record.
In my DAC the Id field has [PXDBIdentity(IsKey = true)]
. It is the only key field.
Here’s some code.
MyDac newDac = graph.MyDac.Insert(new MyDac()) ;
int? tempId = newDac.Id;
graph.MyDac.Cache.Persist(PXDBOperation.Insert);
int? newId = newDac.Id;
tempId is negativ as expected. But newId is alway 0, I’d expect the real value of the newly created entry like in DB. NewDac is still in Cache.Inserted and in DirtyCashes.
If I call graph.Actions.PressSave()
instead of Cache.Persist() newDac.Id is updated and it moves to Cache.Cached. But I have entities in other views that should not be saved at this time.
I am sure, that with other Dac classes the Id is updated after callling Persist(). Does the system check relations to other entities and and therefore may not give back the new Id in my case?
How can I get the real Id of the newly inserted record without PressSave()?