Session.GetObjectByKey(Type, Object) Method
Returns the persistent object that has the specified value for its key property.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
classType | Type | A Type object which represents the type of objects to search for. |
id | Object | An object that represents the persistent object’s key property value. |
Returns
Type | Description |
---|---|
Object | An object which represents the 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 method. Here, session is the Session instance.
using DevExpress.Xpo;
// ...
Person personToDelete = (Person)session.GetObjectByKey(typeof(Person), 152);
personToDelete.Delete();
Firstly, the GetObjectByKey method searches the memory for the object that has the specified value for its key property. If such an object is found, it is not reloaded. To get the up-to-date object from storage, use the overloaded Session.GetObjectByKey method with the alwaysGetFromDb parameter set to true.
Note
The GetObjectByKey method does not find objects until they are saved to a data store.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetObjectByKey(Type, Object) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.