Session.GetObjectByKey(XPClassInfo, 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.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public object GetObjectByKey(
XPClassInfo classInfo,
object id,
bool alwaysGetFromDataStore
)
#Parameters
Name | Type | Description |
---|---|---|
class |
XPClass |
An XPClass |
id | Object | An object which represents the key property’s value of the persistent object. |
always |
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. Null if no objects are found. |
#Remarks
Below is an example of using the GetObjectByKey method. Here, session is the Session instance.
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
// ...
XPClassInfo personClassInfo = session.GetClassInfo(typeof(Person));
Person personToDelete = (Person)session.GetObjectByKey(personClassInfo, 152, true);
personToDelete.Delete();
Firstly, the GetObjectByKey method searches in 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 storage the alwaysGetFromDb parameter must be set to true.
Note
The Get