Session.GetObjectsByKeyFromQuery(XPClassInfo, Boolean, String) Method
Returns reloaded persistent objects from a data store, with key property values obtained via the specified SQL query.
NuGet Package: DevExpress.Xpo
An XPClassInfo object which contains the metadata information of the persistent objects that are retrieved, based on the query’s result set.
true to reload persistent objects from storage, if they are found in memory; otherwise, false.
A String value that specifies a SQL query.
A collection of persistent objects with specified key property values.
The GetObjectsByKeyFromQuery method works as follows:
- Executes the specified SQL query and loads key property values.
- Searches memory for persistent objects with retrieved key property values. If such objects are found, they are not reloaded.
To get up-to-date objects from storage, set the alwaysGetFromDb parameter to
The GetObjectsByKeyFromQuery method may throw the InvalidCastException if a keys’ value and property type do not match. To avoid this error, select key values from a column mapped to the same key property type. The following article describes how XPO maps a CLR type to a database type: Data Types Supported by XPO.
ADO.NET data readers may use different mappings between CLR and database types. XPO works seamlessly with the following key property types: Int32, Int64, Guid. To work with other key property types, ensure that the corresponding ADO.NET data reader returns values of the same type as used in the data model. Use the ExecuteQuery and GetObjectsByKey methods instead of GetObjectsByKeyFromQuery when the type conversion is required.
The GetObjectsByKeyFromQuery method does not find objects, until they are saved to a data store.
For more informatioon about executing SQL queries in XPO, refer to Direct SQL Queries.