All docs
V21.2
21.2
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
The page you are viewing does not exist in version 19.2.
19.1
The page you are viewing does not exist in version 19.1.
18.2
The page you are viewing does not exist in version 18.2.
18.1
The page you are viewing does not exist in version 18.1.
17.2
The page you are viewing does not exist in version 17.2.

Reload Objects and Collections

  • 3 minutes to read

A Session loads objects from a data store and saves them in the Identity Map. XPO uses the Identity Map to ensure that each object is associated with only one record in the data store. There cannot be two different objects (objects with different ids) associated with the same record in the data store.

Object reload means synchronization of object properties with data fields in the corresponding record in the data store. If the value of a field in a data record differs from the value of the corresponding object property, then the value of the object property is overwritten by the value from the data store.

Reload a Persistent Object

Use the Session.Reload method to reload an object. This method does nothing if the object is a new object.

The Session.Reload method updates object properties but does not reload its reference properties and child collections.

Reload Collections

Use the XPBaseCollection.Reload method to reload a collection. This method queries the data store for records that match the collection’s Criteria and reloads corresponding objects. If the data store has a new record that matches the criteria, XPO creates a new object, initializes its properties, and adds to the collection.

Note

XPO uses the Optimistic Concurrency option to track changes in a data store. If Optimistic Concurrency is disabled for a persistent class, the XPBaseCollection.Reload method does not reload properties of objects.

Reload Objects Including Reference Properties and Child Collections

Dispose the Session or UnitOfWork and create a new one to reload all persistent objects at once.

Tip

Use the XPBindingSource component to bind UI controls to XPO data sources in WinForms applications.

How to Bind UI Controls to Data in WinForms Apps

Session - Find Object

The Session.FindObject method searches for a record in the data store. If the record is found, XPO checks whether the corresponding object exists on the Identity Map. If the Optimistic Concurrency option is enabled and the record in the data store has been modified, XPO reloads the object’s properties. If the object is not found on the Identity Map, XPO creates a new object and initializes its properties.

Session - Get Object by Key

The Session.GetObjectByKey method searches for an object on the Identity Map. If the object is found, the method returns the object and does not reload it. If the object is not found on the Identity Map, the GetObjectByKey method searches the data store.

To get the reloaded object directly from the data store, use the GetObjectByKey method with the alwaysGetFromDb parameter set to true.

Use the GetLoadedObjectByKey method to search only loaded objects.