Skip to main content
.NET Standard 2.0+

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

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

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);

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