sorting a TypedView mapped onto a Stored Procedure Resultset

Posts   
 
    
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 03-Aug-2012 06:50:27   

Am I able to use SortClauses to sort a TypedView mapped onto a Stored Procedure Resultset?

If not what how could I sort the resultset (not wanting to do the sorting in the stored procedure)?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Aug-2012 07:26:13   

You either pass a sort parameter to the SP (which you don't want), or you sort the results after fetch. Example using Linq2Objects:

// get SalesByCategory by SP
var results = new SalesByCategoryTPVTypedView();
RetrievalProcedures.FetchSalesByCategoryTPVTypedView<SalesByCategoryTPVTypedView>(results, "Beverages", "1998");

// sort results
var orderedResults = results.OrderByDescending(r => ((SalesByCategoryTPVRow)r).TotalPurchase);
David Elizondo | LLBLGen Support Team
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 03-Aug-2012 08:33:08   

Hi David, thanks for you answer. However, I only have two options calling RetrievalProcedures.GetUserCustomers: a) GetUserCustomers(userid) b) GetUserCustomers(userid, ITransaction)

And both calls return a datatable.

The TypedView is mapped to the stored procedure.

Do I need to map the stored proc differently?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 03-Aug-2012 10:27:27   

A typedview is a datatable. You can simply sort the dataview of the datatable to sort the data in the direction you want. Other than that, if you want to sort in the DB, it has to be sorted inside the stored proc.

Frans Bouma | Lead developer LLBLGen Pro