CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

More handling complex objects in grids

Mike Lorengo and I are having a fantastic dialogue about complex objects and handling the display of their information in grids.  I do recommend you read his post before continuing here.  Don't mind me... I'll wait...

Ok now that you're back I'd like to explain a little deeper on my preference for domain queries that return data tables to populate grids instead of the other methods Mike goes into.  Yes, my main gripe with such a method is the performance concern.  Mike's post, and the feedback he's received the main concern has been about executing many calls instead of one call.

Mike answer's these concerns by giving four ways that you can handle databinding these complex objects:

  1. Return a DataReader of Wine records, and then lazy load the WineVarietal (and Varietal) records in another DataReader as needed
  2. Return a DataReader of Wine records and for each one get another DataReader to load the associated Varietal information
  3. Return a DataReader of Wine records with multiple INNER JOIN's and iterate through the records building the Wine and Varietal information
  4. Issue a batch of Sql Statements for each set of information and use the  IDataReader's  NextResult() method to advance the DataReader to the next result set while building the Wine and Varietal information.

This is all well and good but the point that I wanted to get across is that the purpose of binding the information to the grid is to display summary information.  We're not exposing any specific object calls to the summary information except the load of referential data.  In this case, the end result is that we are using a collection of complex objects as a datatable.  So my point, in the end, is if you are trying to act like a datatable, you might as well be a datatable.  It'll save you all the time of parsing those datareaders and building objects whose functionality you aren't really using.

Great discussion Mike.  I love blogging for the same reasons you do.



Comments

Raymond Lewallen said:

I agree that using a datatable is the way to go. When you need mulitple results sets, a dataset of datatables with relationships and dataviews for filtering and sorting can't be beat in terms of what you get (excluding perf, of course). The dataset, datatable and dataview combinations give you all the functionality you need when binding to a grid. I believe, and I might be wrong, that this combination of objects is the only way to make a master-detail grid work. So why go through all the trouble of obtaining multiple datareaders? What I especially don't like in pre-2.0 framework is the fact that to obtain multiple datareaders, who are connected, you have to use a seperate connection for each one, otherwise you get that dreaded "datareader is already open on this connection" exception.

I think what you have discussed is one main reason why datatables exists, and is absolutely the way to go in these types of scenarios, especially since the functionality already exists to scale out the UI if needed without having to change the backing objects.
# February 3, 2005 8:01 AM

Mike Lorengo said:

Hi Eric,
As usual, there are *many* different ways of accomplishing the same task. I prefer to work at the object model level, allowing me to use the built in instrumentation of my classes such as security, exception logging and statistics reporting.

For my purposes I find that the DataReader/Object Model provides the feature/performance tradeoff that works best.

Good luck in you new role at School One.
# February 6, 2005 7:12 PM
Check out Devlicio.us!

Our Sponsors

Proudly Partnered With