Skip to main content
A newer version of this page is available. .

Saving Persistent Objects

  • 2 minutes to read

To save a persistent object, call its XPBaseObject.Save method. You can also use the session’s Session.Save method to save a single or multiple persistent objects. When you save a persistent object, XPO automatically saves all referenced objects that are aggregated (see AggregatedAttribute) and any referenced newly created non-aggregated objects that don’t yet exist in a data store.

Note

When a Unit of Work is used, there is no need to save each persistent object individually. Call the unit of work’s UnitOfWork.CommitChanges method to save all the changes made to the persistent objects. For more information, see Unit of Work.

XPO allows persistent objects to be saved to one database and each persistent object to one table. Although you can have several XPO sessions connected to different databases and even make a list of objects from different sessions, these objects should not reference each other (the XPO session will throw an error on saving an object which was read by another session).

When XPO saves an object it starts an implicit transaction, if there isn’t one already running. This is necessary to save complex objects. You don’t need to worry about saving these types of data as XPO manages them. If you manually start a transaction, you can discard all the changes made since the transactions start by calling the Session.RollbackTransaction method. For more information on using transactions, see Processing Transactions.