Fetch a parent list with its children in 1 reader

Fetch a parent list with its children in 1 reader

Old forum URL: forums.lhotka.net/forums/t/11105.aspx


vbbeta posted on Monday, January 30, 2012

Hey guys i'm trying to figure out if there is a way to fetch a Parent list (e.g Customer Sales) together with its children (e.g Sales Items) in 1 data-reader without going back to the database and opening a new reader for each child item 

JonnyBee replied on Monday, January 30, 2012

Sure you can, at least with SQL Server.

Just make sure to set MARS (multiple active result sets) on in your connection string.

vbbeta replied on Monday, January 30, 2012

Hi thanks for the answer i appriciate this 

but let me ask you how do i set this up in a DataPortal_Fetch of two class what do i need to pass in at the child level object Is It a reader or a Command

 

JonnyBee replied on Monday, January 30, 2012

Read more about MARS here:

http://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.71%29.aspx

pbusch replied on Monday, January 30, 2012

You might also want to check this dnrTV episode (http://www.dnrtv.com/default.aspx?showNum=60).  Rocky did a presentation on using CSLA.net as a Data Access Layer.  Around 12:40 into the episode he talks how to query for the Parent-Child-GrandChild all from the parent.

tiago replied on Monday, January 30, 2012

Have a look at DeepLoad sample http://cslagenfork.codeplex.com/releases/view/79758

This code was generated by CslaGenFork but you can use it as an example of fecthing a data structure 6 levels deep in a single round trip to the database. And it uses a single data reader...

Copyright (c) Marimer LLC