SP with multiple resultsets

Posts   
 
    
El Barto
User
Posts: 64
Joined: 09-Nov-2006
# Posted on: 08-Sep-2011 09:48:52   

I've written a stored procedure which returns multiple resultsets. I've mapped these resultsets on typedviews. I prefer these strong typed datatables over the regular datatables. I'm able to fill the typedviews, but I have to call the stored procedure for each resultset. I'm also able to fetch all the data at once in a dataset, but this contains the regular datatables. How do I convert/load each datatable in the corresponding typedview? In other words; How do I get the multiple typed views in one database call? Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Sep-2011 12:07:00   

You can fetch the dataSet, and then convert its tables into the TypedView tables, using the Merge method.

var ds = RetrievalProcedures.CustOrderHist2Results("ALFKI");

var resultSet1 = new Resultset1TypedView();
var resultSet2 = new Resultset2TypedView();

resultSet1.Merge(ds.Tables[0]);
resultSet2.Merge(ds.Tables[1]);
El Barto
User
Posts: 64
Joined: 09-Nov-2006
# Posted on: 08-Sep-2011 12:22:33   

True, I tried that. But some columns have a space in their name in the stored procedure. When mapped to a typedview this space is removed. When I merge the tables the resulting table has 2 collumns with a similar name, but only one is filled. For example:

Column name in SP: [Warranty Date] Column name in Typed View: WarrantyDate

When I fetch the multiple resultsets and merge the table from the resulting dataset with a typed view, the resulting typed view has 2 columns: Warranty Date and WarrantyDate with the column Warranty Date filled and the column WarrantyDate empty. So when I try to access the values using the strong typed property WarrantyDate I don't get the proper value.

I know when I proper name the collumns in the SP this would probably be solved. I thought there was maybe a method for loading the datatable in the typed view using the mapping and typeconverters from the designer. It sure would be a nice feature if it isn't allready in there.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Sep-2011 11:28:50   

It's currently not the case that you can fill multiple resultsets from the same proc in one go into typedviews. The main reason is that in our framework to fill typedviews is to see the typedview as the center of what you're going to do. There's no 'fetch proc into these 2 strongly typed constructs' code path.

If we add that, we have 2 ways to fill the same typed view, which we found a little redundant, so we didn't pursue it that way.

We could add it, but it won't be a high priority addition. We did add this feature for linq to sql, as it's the only way to fetch the typedviews in that case so there is knowledge about how to do this, however it's not directly portable to our own framework because our framework uses TDL templates, not lpt templates, and the fetch logic is done different.

If you're using adapter, you could add some code to make this work, as in: set the dataset's datatables to typedview instances before the call, namely in an override of DataAccessAdapterBase.CallRetrievalStoredProcedure, which receives a dataset which is empty. I don't know whether that will work though, because DbDataAdapter.Fill(dataset) simply fills the first datatable with the data from the first resultset, but which table is the 'first' datatable is not defined (I assume the first table added to the dataset, but I don't know for sure)

Frans Bouma | Lead developer LLBLGen Pro
El Barto
User
Posts: 64
Joined: 09-Nov-2006
# Posted on: 09-Sep-2011 11:42:59   

Thanks for the response. I've been using LLBLGen for a couple of years now and this is the first time I stumbled uppon this. So indeed it is not high priority feature.