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

Working with Sessions

  • 2 minutes to read

Once a session has been created and customized, it can be assigned to the Session property of any object which is provided by XPO and is used to represent data (e.g. XPCollection, XPView).

Note

XPO doesn’t require you to specify the working session when you are creating an object - the Session.DefaultSession will be treated as the working session.

To work with your own session, you have to pass it to the constructor of your persistent object(s) and call the base constructor with this session as a parameter.


public class Customer: XPObject {
    public string Name = "";
    public string CompanyName = "";
    public string Phone = "";
    public string Fax = "";
    // Specify a session for the Customer object.
    public Customer(Session session) : base(session) {}
}

The session automatically connects to the data store the first time persistent objects are loaded or saved. To explicitly connect to the data store, use the Session.Connect method. If the session is already connected to a data store, the Connect method does nothing.