Session.GetObjectByKey<ClassType>(Object, Boolean) Method
Returns a persistent object of the type designated by the specified generic type parameter, with the specified value for its key property.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v26.1.dll
NuGet Package: DevExpress.Xpo
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| id | Object | An object that represents the persistent object’s key property value. |
| alwaysGetFromDataStore | Boolean | true, to reload the persistent object from storage if it is found in memory; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| ClassType | A type of objects to search for. |
Returns
| Type | Description |
|---|---|
| ClassType | An object which represents a persistent object with the specified value for its key property. Null if no objects are found. |
Remarks
Below is an example of using the GetObjectByKey<ClassType> method. Here, session is the Session instance.
using DevExpress.Xpo;
// ...
Person personToDelete = session.GetObjectByKey<Person>(152, true);
session.Delete(personToDelete);
Firstly, the GetObjectByKey<ClassType> 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<ClassType> method does not find objects until they are saved to a data store.