Session.GetObjectByKey(XPClassInfo, Object) Method
Returns a persistent object with the specified value of the key property.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.1.dll
NuGet Packages: DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap, DevExpress.Xpo
NuGet Package: DevExpress.Xpo
Declaration
Parameters
Name | Type | Description |
---|---|---|
classInfo | XPClassInfo | An XPClassInfo object which contains the metadata information of the class. |
id | Object | An object which represents the key property’s value of the persistent object. |
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);
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 the data store, 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 snippets (auto-collected from DevExpress Examples) contain references to the GetObjectByKey(XPClassInfo, 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.