Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

ExplicitLoadingAttribute Class

Specifies that the information used to retrieve persistent objects that are referenced by the current property, is included in a query used to load this property.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class ExplicitLoadingAttribute :
    Attribute
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class ExplicitLoadingAttribute :
    Attribute

Remarks

By design, when a property referencing a persistent object is loaded, XPO generates and executes several queries to retrieve this property. One retrieves a reference to the persistent object and the other for each property of the persistent object. It is a recursive process, since the retrieved property in its turn might reference another persistent object. To improve performance by assembling the intermediate queries into one query which is executed only once, use the ExplicitLoadingAttribute. The reference depth of the objects retrieved is controlled by the optional ExplicitLoadingAttribute.Depth parameter. Its default value is 1.

Let us consider a simple example.

class Book : XPObject {
    public string Name {
     get { return fName; }
     set { SetPropertyValue(nameof(Name), ref fName, value); }
 }
 string fName = "";

}
class Article : XPObject {
    [ExplicitLoading()]
    public Book theBook {
     get { return ftheBook; }
     set { SetPropertyValue(nameof(theBook), ref ftheBook, value); }
 }
 Book ftheBook;

}
class Topic : XPObject {
    [ExplicitLoading()]
    public Article theArticle {
     get { return ftheArticle; }
     set { SetPropertyValue(nameof(theArticle), ref ftheArticle, value); }
 }
 Article ftheArticle;

}
class Category : XPObject {
    public Topic theTopic {
     get { return ftheTopic; }
     set { SetPropertyValue(nameof(theTopic), ref ftheTopic, value); }
 }
 Topic ftheTopic;

}

By marking theArticle and theBook properties with the ExplicitLoadingAttribute we have specified that the information about the Topic and Article classes’ properties will be retrieved in one query if the owning class is not deeper than 1 level from the root Category class. Since the Topic class has theArticle property of the Article type marked with the ExplicitLoadingAttribute and the Topic class is one level deep from the root Category class, the information to retrieve its property value will be included in the query. The Article class has theBook property of the Book type marked with the ExplicitLoadingAttribute. In this business model the Book class is two levels deeper than the root Category class, thus information for theBook property will not be included in the query, although this information will be used to generate a new query. If you specify ExplicitLoading(2) attribute for theBook property it will be enough to retrieve all the properties in the Category’s class.

Inheritance

Object
Attribute
ExplicitLoadingAttribute
See Also