When to use BO Collections or Dataset?

When to use BO Collections or Dataset?

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


ward0093 posted on Thursday, August 03, 2006

I am doing a lot of collections lately... and curious to when we should be loading up a collection of BOs and when to use a simple Dataset.

My issues are that my BO Collections... or I mean my BO Chain that is being added to the collection is large (Parent, Childs, GrandChilds, etc) and i am seeing a slight performance hit using a BO Collection.

So at what point (recordcount) do you switch over to using a Dataset?

 

ward0093

ajj3085 replied on Thursday, August 03, 2006

You don't; exposing a DataSet is the opposite of what you're trying to accomplish with a business layer.  As soon as your data structure changes, your UI is now broken.. not to mention that you now need to find some place else to code your business rules.

From your comments, it sounds like you've modeled your business objects on your data tables, which isn't the right way to go (well, if you're buying into Csla and n-tier design at least).  You should be modeling based on behavior.  Its unlikely that your users would load the parent object, edit its child and grandchildren, and save it all as a single transaction.  Likely, they can edit children without needing to edit the parent, etc.  Is there a reason that  you need to load a parent and other children if the user only wants to edit ONE of the children?

Andy

ward0093 replied on Thursday, August 03, 2006

Well... maybe I need to create a couple if different Objects instead of using one object (or a chain of objects) to do everything?
 
This is a Invoice (Parent) -> Child Line Items -> Child Payment Types -> Child Customer.
 
I was loading them up (over 100 of them) into the collection.  Is this correct?  to load up 100~200 objects into a collection?
 
curious if I am doing this correctly?
 
ward0093

JonM replied on Thursday, August 03, 2006

I would recommend trying to break that up a bit.  Do you really need to load and manipulate all of those at once?  I use the lightweight read-only collections a lot.

xal replied on Thursday, August 03, 2006

ward,
There's nothing wrong with that if that is your requirement...

If you used a datatable, you'd still be loading 100~200 datarow objects in a datatable, which is also a collection (of datarows :) )

Andrés

ajj3085 replied on Thursday, August 03, 2006

Ahh... I'm also delving into the Invoice world.

What is your use case?  Is it editing the Invoice?  If that's the case, a parent Invoice would contain a collection of LineItems.  I'm not sure why LineItems need a collection of payment types.. could you elaborate on what you're trying to accomplish?

The customer should be a readonly object at most; you can have a Customer Property on your Invoice to set / get the customer for which the invoice is meant.  Alternately you can just keep a customer id on the invoice, and expose properties on the invoice like Customer Name, Address, etc.

There are quite a few ways to go, but if you post the requirements from your use cases, I'm sure others here can help.

Andy

ward0093 replied on Friday, August 04, 2006

Sorry... I wasn't clear

My BO Setup is:

ParentInvoice Object contains a Property for the following:

LineItemsCol (child to Invoice)

PaymentTypesCol (child to Invoice)

CustomerBO (child to Invoice)

 

So I guess I am simply asking what kind of performance difference am I going to see if I load up a InvoicesCollection Object (of the structure above) versus loading up a DataSet?

ward0093

 

 

xal replied on Friday, August 04, 2006

For that number of children, the difference will not be huge. But csla should be always faster.

Although, if you're running tests, you need to consider that the dataportal has a small overhead. That has nothing to do with the time the objects load, so if you want to run accurate tests you could load the dataset through the dataportal and measure how much time it takes to retrieve the dataset and the csla structure.
Also, datasets are much much bigger when serialized, so that is a big con for them.
One last thing, consider that bos generally have rules, so that's another thing you need to consider in measuring. Also, in 2.1 rules can be loaded per type, instead of per instance, and that is a big improvement.

Andrés

ward0093 replied on Saturday, August 05, 2006

Your right!.... I just loaded up 100 Invoice Objects with all the children and grandchildren... and it was FAST!!!

I am a little amazed... I had, in my mind, that Object Creation and Loading had some sort of overhead.

anyways... it is great... and with high performance.

thanks for your help,

ward0093

Copyright (c) Marimer LLC