Best tact for Hierarchical queries

Best tact for Hierarchical queries

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


csmith1 posted on Thursday, March 08, 2012

I need to query an EditableRootList by hierarchical child attributes.

An example from Using CSLA would be a  Invoice->LineItems->LineItem.

I would like to return all Invoices for this month that have an LineItem Amount over $500.00.

Should I make a Command or this a Unit of Work?

I do not see in Using CSLA an example of how tackle this type of problem.

 

RockfordLhotka replied on Thursday, March 08, 2012

You'll obviously have an InvoiceList object that is the list of Invoice objects right? Or maybe a list of read-only InvoiceInfo objects?

The fetch method for the InvoiceList object is where you'd execute the database query necessary to retrieve the filtered list of invoice data. All the real work should occur in the query (in the database).

csmith1 replied on Thursday, March 08, 2012

I understand the work will be done in the server side in my case in the DAL. Usually I have seen top down query where one selects an invoice. Then selects invoice row. I like select and return a sub-set invoices with the children already loaded.  I am thinking of creating a command that contains the criteria for the root and each child in hierarchy. I have a view in the db that joins all the tables together. I would select against the view. Then walk down the results filling in the selected parent then selected children then selected grandchildren. I would think this is a fairly common problem. Was not sure if there was some advantage to using the unit of work over the command. I was wonder if someone had come up with a different way to return result in a hierarchical set.   

tiago replied on Thursday, March 08, 2012

Hi,

Have a look at DeepLoad sample v.2.0.0

This sample is generated by CslaGenFork. You can use the generated code as a guide. CslaGenFork doesn't support your needs directly, meaning you would have to edit the generated stored procedure in order return only Invoide WHERE "LineItem Amount over $500.00". Besides that change in the search criteria, CslaGenFork can generate code to fetch all data in a single round trip to the database. If you don't like code generators, have a look at the sample to see how it's done.

Copyright (c) Marimer LLC