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

XPBaseCollection.LoadingEnabled Property

Gets or sets whether loading of data from a data store to the collection is enabled.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v18.2.dll

Declaration

[DefaultValue(true)]
public bool LoadingEnabled { get; set; }

Property Value

Type Default Description
Boolean **true**

true if data can be loaded; otherwise, false.

Remarks

If this property is set to true and the collection’s contents are accessed for the first time, the collection is automatically populated with data from a data store. If the collection has already been loaded, setting the LoadingEnabled property to true calls the collection’s XPBaseCollection.Reload method.

Setting the LoadingEnabled property to false disables the automatic load. Calling the XPBaseCollection.Load or XPBaseCollection.LoadAsync method when the LoadingEnabled property is set to false will not load data from the data store.

Note that when an XPCollection is created using a constructor with the criteriaEvaluationBehavior parameter, the collection is loaded immediately and its LoadingEnabled property is automatically set to false. After that, the collection cannot be reloaded using the XPBaseCollection.Reload method, since object loading is disabled.

Example

In the following example a new XPCollection collection is created. Its XPBaseCollection.LoadingEnabled property is set to false thus disabling the automatic load of data from an underlying data store (from the “Person” table in the database). Such unbound collections can be used to store lists of objects when there is no need to retrieve data from the underlying data store.

using DevExpress.Xpo;

// Create a collection of Person objects.
XPCollection collection = new XPCollection(typeof(Person));
// Disable automatic loading.
collection.LoadingEnabled = false;
collection.Add(new Person("John Black", true));
collection.Add(new Person("Mary Stewart", false));
//...
collection.Session.Save(collection);

// A custom XPobject
class Person : XPObject {
    // ...
    public Person(string name, bool isMale) { ...}
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the LoadingEnabled property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also