How to call Retrieval Procedures Async?

Posts   
 
    
Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 13-Jul-2016 20:14:15   

I'm using v5.0.2 build 20-May-2016 with SQL Server 2008.

I've reversed engineered a retrieval stored procedure (1 resultset) as well as the resultset to a TypedView.

Now I want to retrieve the typed rows (using the TypedViewRow type generated by LLBLGen) asynchronously but can't figure out how to do it. I see a section in the docs about projecting a DbDataReader resultset but that seems like its for projecting to a custom object.

How do I do this?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 13-Jul-2016 22:39:18   

RetrievalProcedures has methods (GetStoredProcedureCallNameCallAsQuery) to return the SP query, to be fetched by other methods, like FetchDataReader or FetchTypedView, the first has an Async overloads.

Example:

using( DataAccessAdapter adapter = new DataAccessAdapter() )
{
    IDataReader reader = adapter.FetchDataReaderAsync( 
        RetrievalProcedures.GetCustOrderDetailCallAsQuery(10254), 
        CommandBehavior.CloseConnection, CancellationToken);
    while( reader.Read() )
    {
        // some code.
    }
    // close reader, will also close connection
    reader.Close();
}

Also it's recommended to use QuerySpec for that matter, especially that it will make the projection much easier.

Example:

    var qf = new QueryFactory();
    var rows = await new DataAccessAdapter().FetchQueryFromSourceAsync(qf.GetCustOrdersDetailQsTypedViewProjection(), RetrievalProcedures.GetCustOrdersDetailCallAsQuery(10254));

Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 14-Jul-2016 00:37:03   

I'm sorry but I still don't understand. I want an async version of something that will return typedview rows, not datareader rows.

And, I don't understand what that second snippet of code does. My QueryFactory does not have any FetchQuery... method for my stored procedures. Looking at the generated QueryFactory code, it seems it only generates factory methods that return entity types and not typedview types.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 14-Jul-2016 11:17:32   

Emmanuel wrote:

I'm sorry but I still don't understand. I want an async version of something that will return typedview rows, not datareader rows.

That's what Walaa's example does simple_smile

See: http://www.llblgen.com/Documentation/5.0/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/Using%20TypedViews,%20TypedLists%20and%20Dynamic%20Lists/gencode_usingtypedview_adapter.htm

Scroll down to 'OutputType: PocoWithQuerySpecQuery'. ->

OutputType: PocoWithQuerySpecQuery

For QuerySpec, retrieving a poco typed view mapped onto a stored procedure resultset comes down to using two parts:

  • Obtain the projection lamdba from the QueryFactory. This projection is produced by the method TypedViewNameTypedViewProjection
  • Pass it to the method in RetrievalProcedures which fetches the actual typed view.

This looks like the following:

var results = RetrievalProcedures.FetchCustomersOnCountryQsTypedView(
            new QueryFactory().GetCustomersOnCountryTypedViewProjection(), "USA");

Alternatively, you can use FetchQueryFromSource to do the same:

List<CustomersOnCountryRow> results;
using(var adapter = new DataAccessAdapter())
{
    results = adapter.FetchQueryFromSource(
                new QueryFactory().GetCustomersOnCountryTypedViewProjection(), 
                RetrievalProcedures.GetCustomersOnCountryCallAsQuery("USA");
}

The async variant is simply calling the Async variant of FetchQueryFromSource and awaiting it, so it then becomes:

List<CustomersOnCountryRow> results;
using(var adapter = new DataAccessAdapter())
{
    results = await adapter.FetchQueryFromSourceAsync(
                new QueryFactory().GetCustomersOnCountryTypedViewProjection(), 
                RetrievalProcedures.GetCustomersOnCountryCallAsQuery("USA");
}

And, I don't understand what that second snippet of code does. My QueryFactory does not have any FetchQuery... method for my stored procedures.

The fetch method is on the adapter, not the query factory wink

It produces a projection, and a query specification, then passes them to FetchQueryFromSource/FetchQueryFromSourceAsync().

Looking at the generated QueryFactory code, it seems it only generates factory methods that return entity types and not typedview types.

Did you set the output type of the typed view to PocoWithQuerySpecQUery? By default it's TypedDataTable. You can switch the default in the project settings -> conventions -> LLBLGen Pro Runtime Framework.

Frans Bouma | Lead developer LLBLGen Pro
Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 14-Jul-2016 13:00:34   

Thanks, PocoWithQuerySpec wasn't set.