Hierarchical data with BO's

Posts   
 
    
Posts: 22
Joined: 20-Sep-2006
# Posted on: 06-Nov-2006 15:09:26   

I'm using LLBL to generate a DAL layer and CSLA to construct my BO's

I've run across a problem that I'm hoping someone else has dealt with at one time or another

I have an object RO that has two children ROPart/ROLabor

These RO is 1:m with both children. ROPart/Labor never exist without RO, but have different properties rules and behaviors thus they are a separate classes.

So the root of my "problem" is how to fetch the data into these classes.

If I pull a collection, which I can then loop back through and pass off the appropriate info...

Or I could have each ROPart and Labor item fetch its own data, this seems expensive if we load a large collection of RO objects.

Anyone have any pointers, thoughts or suggestions?

Thanks, Justin

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 06-Nov-2006 15:22:45   

Hello,

You can fetch the RO entity creating a prefetch path on RoPart and RoLabor. If you use the adapter scenario you can use adapter.fetchEntity(RoEntity,PrefetchPath). Then you will be able to access to RoPart and RoLabor EntityCollection from RO(using RO.RoPart for example).

Posts: 22
Joined: 20-Sep-2006
# Posted on: 06-Nov-2006 15:36:16   

jbb wrote:

Hello,

You can fetch the RO entity creating a prefetch path on RoPart and RoLabor. If you use the adapter scenario you can use adapter.fetchEntity(RoEntity,PrefetchPath). Then you will be able to access to RoPart and RoLabor EntityCollection from RO(using RO.RoPart for example).

Well this is sort of what I'm doing now.


 EntityCollection<RoEntity> _ro = new EntityCollection<RoEntity>(new RoEntityFactory());
            IPrefetchPath2 _path = new PrefetchPath2((int)EntityType.RoEntity);
            _path.Add(RoEntity.PrefetchPathRoParts);
            _path.Add(RoEntity.PrefetchPathRoLabor);
            IRelationPredicateBucket _bucket = new RelationPredicateBucket(RoFields.Roid == _id);
        
        

            DataCalls.FetchCollection(_ro, _bucket, _path);
        
            return _ro;

The problem, is that it uses JOINS when I fetch this, so I don't have Parts or Labor as separate graphs, or separate parts of the graph, not sure that I want to have it this way... just unsure what's the best way to feed the data to the children.

I can create a datatable, loop through the collection and fill the table with the appropriate details and then feed it to the child, but again, I'm not sure this is the best way of handling.

Of course, I could be missing something simpler... that's why I'm asking simple_smile

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 06-Nov-2006 15:51:17   

You don't need to use an EntityCollection if you only want one Entity. You can use :


_ro=new RoEntity(_id);
IPrefetchPath2 _path = new PrefetchPath2((int)EntityType.RoEntity);
_path.Add(RoEntity.PrefetchPathRoParts);
_path.Add(RoEntity.PrefetchPathRoLabor);
DataCalls.FetchEntity(_ro,_path);
return _ro;

It will also fetch the child Entities. After If you use _ro.RoPart() you can parse the entitycollection to have all RoPart entity you need.

Posts: 22
Joined: 20-Sep-2006
# Posted on: 06-Nov-2006 16:10:41   

Ahh, now I see. Thanks!

Quick follow up. There will be times that I need to fetch a collection of RO's and depending on how we decide to implement the UI, we may need to fetch the children at the same time.

If we go about doing this, is there a similar method to do this on the collection?

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 06-Nov-2006 16:16:20   

To do this on a collection it's the same way that you wrotte before:


EntityCollection<RoEntity> _ro = new EntityCollection<RoEntity>(new RoEntityFactory());
IPrefetchPath2 _path = new PrefetchPath2((int)EntityType.RoEntity);
_path.Add(RoEntity.PrefetchPathRoParts);
_path.Add(RoEntity.PrefetchPathRoLabor);
DataCalls.FetchEntityCollection(_ro, null, _path);
return _ro;

by this, you will have all Ro Entities and all childs fetched.