Back to Devexpress

Session.GetObjectsByKeyFromQuery(XPClassInfo, Boolean, String) Method

xpo-devexpress-dot-xpo-dot-session-dot-getobjectsbykeyfromquery-x28-devexpress-dot-xpo-dot-metadata-dot-xpclassinfo-system-dot-boolean-system-dot-string-x29.md

latest4.2 KB
Original Source

Session.GetObjectsByKeyFromQuery(XPClassInfo, Boolean, String) Method

Returns reloaded persistent objects from a data store, with key property values obtained via the specified SQL query.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public ICollection GetObjectsByKeyFromQuery(
    XPClassInfo classInfo,
    bool alwaysGetFromDataStore,
    string sql
)
vb
Public Function GetObjectsByKeyFromQuery(
    classInfo As XPClassInfo,
    alwaysGetFromDataStore As Boolean,
    sql As String
) As ICollection

Parameters

NameTypeDescription
classInfoXPClassInfo

An XPClassInfo object which contains the metadata information of the persistent objects that are retrieved, based on the query’s result set.

| | alwaysGetFromDataStore | Boolean |

true to reload persistent objects from storage, if they are found in memory; otherwise, false.

| | sql | String |

A String value that specifies a SQL query.

|

Returns

TypeDescription
ICollection

A collection of persistent objects with specified key property values.

|

Remarks

The GetObjectsByKeyFromQuery method works as follows:

  1. Executes the specified SQL query and loads key property values.
  2. 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 true.

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.

Note

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.

See Also

GetObjectsByKeyFromSproc(XPClassInfo, Boolean, String, OperandValue[])

GetObjectsByKey

GetObjectByKey

KeyAttribute

Session Class

Session Members

DevExpress.Xpo Namespace