Getting default values from database after saving an entity

I have default values set for fields at the database level (using SQL server). For example, there is a CreatedOn datetime field with a default of GetDate(). When I save an entity in Aurelius, whether using a POST via the web or a direct, The saved object (JSON when accessing via the web) does not contain the default values, even though the database did create the default value. I know that generator retrieves unique ids, but is there a way that the response object/the object after save will get default values for other fields?

I also tried doing this manually, e.g., I create a service that takes in the entity, say Customer. The service implemenation has the following code - you see I am trying different ways to return the Customer with the default values. The default values DO exist in the database when it is saved, they just don't return in the result set. If I make a subsequent call to Find Customer, it will return the default data, but not a Find Customer in the same call like that below. Your help is appreciated.

function TMyService.CreateCustomer(newcustomer: Tcustomer): Tcustomer;
var customerid : TGUID;
//result := TCustomer -- this does not return the default fields (except CustomerCD)
customerID := newinvitee.CustomerID;
//see if by finding customer the default fields are returned - update - it does not
Result := TXDataOperationContext.Current.GetManager.Find<TCustomer(customerID);

You have to explicitly call Manager.Refresh(SavedObject) to retrieve recent data from database and update the object properties accordingly.


Thanks Wagner but I had tried that and it didn't work (originally I had the refresh, and then tried find when that didn't work. I just confirmed again - the devault values in the customer object are not changing after refresh, but in debug mode I can see the values in the DB before refresh and they are correct).

The biggest issue is that there is an automatic GUID and both the CRUD endpoint in Aurelias and custom implemented code above return the WRONG value for the GUID. For example, in the database, the GUID is B2B97988-30EE-EB11-A7AD-A04A5E465EC3, but what gets returned after the save is 74757873-DD32-4F19-AD9B-93E0BB756524. The definition for the column InviteID is
[Id('FCustomerID', TIdGenerator.Guid)]
TCustomer = class
[Column('CustomerID', [TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FCustomerID: TGuid;

Help is appreciated. Note that if the autogenerated ID is an integer, it returns the correct integer, but not if it is a GUID.

I think this is a bug in Xdata with the tidgenerator.guid definition in the ID field. Basically none of the refresh statements worked because Xdata is creating its own GUID even though the column definition is no insert and therefore the CustomerID GUI in the object does not match the one in the database, so when it tries to refresh it doesn't find a matching record. I switched the column type to a sequential integer and it works as specified. Sort of a pain that Xdata does not work with auto-generated GUIDs from the database.

Aurelius doesn't refresh id values, that's by design. The object is represented by its id, which must never change, otherwise of course it's a different object. If you do a further Find, you will see Aurelius will retrieve the new GUID as a new object, having both instances in your manager (the old GUID, and the new one).

This is by design. And yes, Aurelius TIdGenerator.Guid is supposed to have the GUID generated at client side (Aurelius side), not from the database.