Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> How to call Retrieval Procedures Async?
 

Pages: 1
LLBLGen Pro Runtime Framework
How to call Retrieval Procedures Async?
Page:1/1 

  Print all messages in this thread  
Poster Message
Emmanuel
User



Location:
Ottawa, Canada
Joined on:
13-Jan-2006 23:14:31
Posted:
167 posts
# 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?
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14584 posts
# 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:
Code:
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:
Code:
    var qf = new QueryFactory();
    var rows = await new DataAccessAdapter().FetchQueryFromSourceAsync(qf.GetCustOrdersDetailQsTypedViewProjection(), RetrievalProcedures.GetCustOrdersDetailCallAsQuery(10254));


  Top
Emmanuel
User



Location:
Ottawa, Canada
Joined on:
13-Jan-2006 23:14:31
Posted:
167 posts
# 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.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37860 posts
# 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 Regular Smiley

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'. ->
Quote:

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:

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

Alternatively, you can use FetchQueryFromSource to do the same:

Code:
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:

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



Quote:

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().

Quote:

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
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Emmanuel
User



Location:
Ottawa, Canada
Joined on:
13-Jan-2006 23:14:31
Posted:
167 posts
# Posted on: 14-Jul-2016 13:00:34.  
Thanks, PocoWithQuerySpec wasn't set.
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.