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.v24.2.dll
Declaration
Remarks
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 Book {
get { return fBook; }
set { SetPropertyValue(nameof(Book), ref fBook, value); }
}
Book fBook;
}
class Topic : XPObject {
[ExplicitLoading()]
public Article Article {
get { return fArticle; }
set { SetPropertyValue(nameof(Article), ref fArticle, value); }
}
Article fArticle;
}
class Category : XPObject {
[ExplicitLoading()]
public Topic Topic {
get { return fTopic; }
set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}
Topic fTopic;
}
By marking the Article and the Book 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 the Article 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 the Book 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 the Book property it will be enough to retrieve all the properties in the Category
‘s class.