Fetching queries
Queries can be fetched in different ways, depending on their type and the used template group (Adapter or SelfServicing).
Adapter
For adapter, extension methods have been added for IDataAccessAdapter, to execute queries using the adapter the method is called on. The extension methods are specified in the Adapter specific namespace SD.LLBLGen.Pro.QuerySpec.Adapter. It's therefore key your code file contains a using / Imports statement for this namespace to use one of the methods below.
A DynamicQuery<T> is a subtype of DynamicQuery and therefore all methods which accept a DynamicQuery will also accept a DynamicQuery<T>.
- FetchQuery<TEntity>(EntityQuery<TEntity> query). This method fetches the query specified and returns an EntityCollection<TEntity> instance typed as IEntityCollection2.
- FetchQuery<TEntity, TCollection>(EntityQuery<TEntity> query, TCollection toFill). This method fetches the query specified into the collection toFill and returns toFill. All values in toFill are kept as-is.
- FetchQuery (DynamicQuery query). This method is the raw fetch method for a dynamic query. It will simply fetch the query with a projection fetch and will return the results as a List<object[]> object, where each row of the query will be returned as an object array.
- FetchQuery<T>(DynamicQuery<T> query). This method will return a List<T> from the query specified, and will use the set projector func inside the query to convert the results of the query into instances of T.
- FetchFirst<TEntity>(EntityQuery<TEntity> query). This method fetches the first element of the query specified and returns it typed as TEntity. If there's no limit specified on query, it's set to 1. Similar to Linq's FirstOrDefault() method.
- FetchFirst<T>(DynamicQuery<T> query). This method fetches the first element of the query specified and returns it typed as T. If there's no limit specified on query, it's set to 1. Similar to Linq's FirstOrDefault() method.
- FetchSingle<TEntity>(EntityQuery<TEntity> query). This method is similar to FetchFirst(query) however, it expects a resultset of 1 element, similar to Linq's Single() method. It doesn't set the limit to 1.
- FetchSingle<T>(DynamicQuery<T> query). This method is similar to FetchFirst(query) however, it expects a resultset of 1 element, similar to Linq's Single() method. It doesn't set the limit to 1.
- FetchScalar<TValue>(QuerySpec query). This method sees the specified query as a scalar query and prepares it as such. It fetches the query using a limit of 1 and returns the value typed as TValue. If the scalar can return nullable values, specify TValue as Nullable<Of T>.
- FetchAsDataTable(DynamicQuery query). This method fetches the query into a new DataTable and returns the filled datatable with columns as a result. If query has nested queries in the projection, they're ignored.
- FetchAsDataTable(DynamicQuery query, DataTable destination). Same as non-generic variant, except the data is now fetched into the specified datatable destination which is also returned by the method.
- FetchAsProjection(DynamicQuery query, IGeneralDataProjector projector). This method fetches the query specified using the projector specified. This method can help when a custom projector has to be used when fetching the results of a query. Method will ignore nested queries.
- FetchAsDataReader(DynamicQuery query, CommandBehavior behavior). This method fetches the query specified as an open IDataReader. The query is the raw SQL query and doesn't contain any projection logic embedded in the select Lambda in the query. The DataReader returned is open and should be closed and disposed by the caller. Nested queries are ignored.
- FetchQueryFromSource<T>(DynamicQuery<T> projectionDefinition, IRetrievalQuery source). This method fetches the query which projection is specified in the projectionDefinition, from the source query specified. Typically used to fetch a typed view from a stored procedure source.
SelfServicing
For SelfServicing, extension methods are defined for IDao and IEntityCollection, to execute a defined query. The extension methods are specified in the SelfServicing specific namespace SD.LLBLGen.Pro.QuerySpec.SelfServicing. It's therefore key your code file contains a using / Imports statement for this namespace to use one of the methods below. For IDao instances, the TypedListDAO class can be used, or any other DAO class from the generated code.
- IEntityCollection.GetMulti(EntityQuery<TEntity> query).This method fetches the query specified and fills the IEntityCollection object GetMulti is called on. If the GetMulti has to be taken place inside a transaction, add the IEntityCollection object to a transaction. It's required that IEntityCollection can contain TEntity typed elements.
- EntityQuery<TEntity>.GetFirst(). This method fetches the first entity from the entity query it's called on and returns that element as TEntity. If no limit is set, it's set to 1. It's equal to Linq's FirstOrDefault() method.
- EntityQuery<TEntity>.GetFirst(Transaction t). Equal to EntityQuery<TEntity>.GetFirst(), however with this version the fetch takes place inside the transaction t
- IDao.GetFirst(DynamicQuery<T> query). This method fetches the first element from the query specified using the IDao instance (e.g. TypedListDAO) it's called on and returns that element as T. If no If no limit is set, it's set to 1. It's equal to Linq's FirstOrDefault() method.
- IDao.GetFirst(DynamicQuery<T> query , Transaction t). Equal to IDao.GetFirst(DynamicQuery<T> query) however with this version the fetch takes place inside the transaction t.
- EntityQuery<TEntity>.GetSingle(). This method is similar to IDao.GetFirst() however, it expects a resultset of 1 element, similar to Linq's Single() method. It doesn't set the limit to 1.
- EntityQuery<TEntity>.GetSingle(Transaction t). This method is similar to IDao.GetFirst(transaction) however, it expects a resultset of 1 element, similar to Linq's Single() method. It doesn't set the limit to 1.
- IDao.GetScalar<T>(DynamicQuery query). This method sees the specified query as a scalar query and prepares it as such. It fetches the query using a limit of 1 and returns the value typed as TValue. If the scalar can return nullable values, specify TValue as Nullable<T>.
- IDao.GetScalar<T>(DynamicQuery query, Transaction t). Equal to IDao.GetScalar<T>(DynamicQuery query) however with this version the fetch takes place inside the transaction t.
- IDao.FetchQuery(DynamicQuery query). This method is the raw fetch method for a dynamic query. It will simply fetch the query with a projection fetch and will return the results as a List<object[]> object, where each row of the query will be returned as an object array.
- IDao.FetchQuery(DynamicQuery query, Transaction t). Equal to IDao.FetchQuery(DynamicQuery query) however with this version the fetch takes place inside the transaction t
- IDao.FetchQuery(DynamicQuery<T> query). This method will return a List<T> from the query specified, and will use the set projector func inside the query to convert the results of the query into instances of T.
- IDao.FetchQuery(DynamicQuery<T> query, Transaction t). Equal to IDao.FetchQuery(DynamicQuery<T> query) however with this version the fetch takes place inside the transaction t
- IDao.FetchAsDataTable(DynamicQuery query). This method fetches the query into a new DataTable and returns the filled datatable with columns as a result. If query has nested queries in the projection, they're ignored.
- IDao.FetchAsDataTable(DynamicQuery query, DataTable destination). Same as non-generic variant, except the data is now fetched into the specified datatable destination which is also returned by the method.
- IDao.FetchAsDataTable overloads which also accept a transaction t. Same as overloads which don't accept a transaction t, except the fetch is now taking place inside the transaction t.
- IDao.FetchAsProjection(ITransaction transactionToUse, DynamicQuery query, IGeneralDataProjector projector). This method fetches the query specified using the projector specified. This method can help when a custom projector has to be used when fetching the results of a query. Method will ignore nested queries.
- IDao.FetchAsDataReader(ITransaction transactionToUse, DynamicQuery query, CommandBehavior behavior). This method fetches the query specified as an open IDataReader. The query is the raw SQL query and doesn't contain any projection logic embedded in the select Lambda in the query. The DataReader returned is open and should be closed and disposed by the caller. Nested queries are ignored.
- IDao.FetchQueryFromSource<T>(DynamicQuery<T> projectionDefinition, IRetrievalQuery source). This method fetches the query which projection is specified in the projectionDefinition, from the source query specified. Typically used to fetch a typed view from a stored procedure source.
- IDao.FetchQueryFromSource<T>(ITransaction t, DynamicQuery<T> projectionDefinition, IRetrievalQuery source). Same as IDao.FetchQueryFromSource<T>(DynamicQuery<T> projectionDefinition, IRetrievalQuery source) however with this version the fetch takes place inside the transaction t.