Skip to main content
.NET Framework 4.6.2+

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.v24.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) { ...}
}
See Also