Session.PreFetch<T>(IEnumerable<T>, String, IEnumerable) Method
Enforces loading data for associated collections.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public void PreFetch<T>(
IEnumerable<T> objects,
string collectionInObjects,
IEnumerable collectionsContent
)
#Parameters
Name | Type | Description |
---|---|---|
objects | IEnumerable<T> | An IEnumerable list of parent objects. |
collection |
String | A string which is the name of the associated collection property. |
collections |
IEnumerable | An IEnumerable list of the collection’s content. If the collection |
#Type Parameters
Name | Description |
---|---|
T | The type of elements in the list of parent objects. |
#Remarks
By default, data is loaded automatically when you access a nested collection for the first time. When the PreFetch<T> method is called, all data for the specified collection is loaded at once. No additional SQL queries for this data will be performed later.
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
// ...
XPCollection<Person> people = new XPCollection<Person>(session);
XPCollection<PhoneNumber> phoneNumbers = new XPCollection<PhoneNumber>(session);
session.PreFetch<Person>(people, nameof(PhoneNumbers), phoneNumbers);