Back to Devexpress

How to: Obtain a Collection of Persistent Objects by a Set of Their IDs

xpo-3239-examples-how-to-obtain-a-collection-of-persistent-objects-by-a-set-of-their-ids.md

latest1.8 KB
Original Source

How to: Obtain a Collection of Persistent Objects by a Set of Their IDs

  • Aug 24, 2020

To retrieve persistent objects by their key values (IDs), call the Session.GetObjectsByKey method.

csharp
Session session1;
// Session initialization
// ...

// An array of key values
object[] idList = new object[] { 1, 2, 3 };

// Retrieves PersistentClass objects with the specified key values
ICollection collection = 
    session1.GetObjectsByKey(session1.GetClassInfo<PersistentClass>(), idList, true);
vb
Dim session1 As Session
' Session initialization
' ...

' An array of key values
Dim idList() As Object = { 1, 2, 3 }

' Retrieves PersistentClass objects with the specified key values
Dim collection As ICollection = _
session1.GetObjectsByKey(session1.GetClassInfo(Of PersistentClass)(), idList, True)

To retrieve persistent objects by the key values that are obtained via direct SQL queries or stored procedures, call the Session.GetObjectsByKeyFromQuery or Session.GetObjectsByKeyFromSproc method respectively.

To retrieve a specific persistent object by its key value, call the Session.GetObjectByKey<ClassType> or Session.GetObjectByKey method.

See Also

FindObject