xpo-devexpress-dot-xpo-88f935ca.md
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.v25.2.dll
NuGet Package : DevExpress.Xpo
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class ExplicitLoadingAttribute :
Attribute
<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Field, Inherited:=True)>
Public NotInheritable Class ExplicitLoadingAttribute
Inherits Attribute
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;
}
Class Book
Inherits XPObject
Public Property Name() As String
Get
Return fName
End Get
Set(ByVal value as String)
SetPropertyValue(NameOf(Name), fName, value)
End Set
End Property
Private fName As String = ""
End Class
Class Article
Inherits XPObject
<ExplicitLoading()> _
Public Property Book() As Book
Get
Return fBook
End Get
Set(ByVal value as Book)
SetPropertyValue(NameOf(Book), fBook, value)
End Set
End Property
Private fBook As Book
End Class
Class Topic
Inherits XPObject
<ExplicitLoading()> _
Public Property Article() As Article
Get
Return fArticle
End Get
Set(ByVal value as Article)
SetPropertyValue(NameOf(Article), fArticle, value)
End Set
End Property
Private fArticle As Article
End Class
Class Category
Inherits XPObject
<ExplicitLoading()> _
Public Property Topic() As Topic
Get
Return fTopic
End Get
Set(ByVal value as Topic)
SetPropertyValue(NameOf(Topic), fTopic, value)
End Set
End Property
Private fTopic As Topic
End Class
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.
Object Attribute ExplicitLoadingAttribute
See Also