The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.GetObjectByKey(Type, Object, Boolean) Method

Returns the reloaded persistent object with the specified value of the key property from a data store.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

public object GetObjectByKey(
    Type classType,
    object id,
    bool alwaysGetFromDataStore
)
Public Function GetObjectByKey(
    classType As Type,
    id As Object,
    alwaysGetFromDataStore As Boolean
) As Object
public object GetObjectByKey(
    Type classType,
    object id,
    bool alwaysGetFromDataStore
)
Public Function GetObjectByKey(
    classType As Type,
    id As Object,
    alwaysGetFromDataStore As Boolean
) As Object

Parameters

Name Type Description
classType Type

A Type object which represents the type of objects to search for.

id Object

An object which represents the key property's value of the persistent object.

alwaysGetFromDataStore Boolean

true to reload the persistent object from storage if it is found in memory; otherwise, false.

Parameters

Name Type Description
classType Type

A Type object which represents the type of objects to search for.

id Object

An object which represents the key property's value of the persistent object.

alwaysGetFromDataStore Boolean

true to reload the persistent object from storage if it is found in memory; otherwise, false.

Returns

Type Description
Object

An object which represents the persistent object with the specified value of the key property.

Returns

Type Description
Object

An object which represents the persistent object with the specified value of the key property.

Remarks

Below is an example of using the GetObjectByKey method. Here, session is the Session instance.

using DevExpress.Xpo;
// ...
Person personToDelete = (Person)session.GetObjectByKey(typeof(Person), 152, true);
personToDelete.Delete();

Firstly, the GetObjectByKey method searches the memory for the object with the specified value of the key property. If such an object is found, it is not reloaded. To get the up-to-date object from the data store the alwaysGetFromDb parameter must be set to true.

Note

The GetObjectByKey method does not find objects until they are saved to a data store.

See Also