StrataFrame Forum

Business Object from Joined Tables

http://forum.strataframe.net/Topic25388.aspx

By Ger Cannoll - 12/11/2009

I have many requirements to be able to show on a ListView/Combobox the results from multiple joined tables. (e.g.Show Transactions but join in the Stock Description from a joined file). I have gone through a lot of the threads here to get hints , and have it working fine on a Combobox , but would like to ensure there are no Gotchas for any of the other list types , or maybe there is a better way.

1. Say my data is required from two Tables, Tran and Products, where Products gives the description
2. I have set up a 'Dummy' business Object which will be used for ALL my Joined Tables (Query ? Can I do this with just one Dummy Business Object for ALL my lists)
3. I have a Stored Proccdure which Joins the Tables Tran and Products
4. I specify the Dummy Business Object as the BusinessObjectType  in the PopulationDataSourceSettings 9With a different Stored procedure depending on the  Tables)
(When entering the Columns, I type in the column names as they will not be in the buisness Object when it is initially set up)
5. My main concern is that I am using in effect  a Multi Table Business Object (whereas when Business Objects are being set up they are limited to One Table only) and wonder if this will cause any problems in SF

 

Any comments would be helpful

By Edhy Rijo - 12/11/2009

Hi Gerard,



To show a field description you can do any of the following:

1) Add a Custom Field Property to your main BO that will call an Escalar method to get the description and you will use this new field whenever you need to show the description. This will work just fine as long as you are not showing many records since it will do a trip to the database to get the description for every field loaded in the BO, this is no good for reports but when showing few records it is acceptable.



1a) Using the above method, if you need to show many records you can always have a LookupBO in which you will have all the records to be look at for the description and instead of using an Excalar method you will simply LookupBO.Seek() to find the description record and update the Custom Field Property.



2) Another option for reporting or Browse Dialog is to use an SQL View with your JOIN condition and create a BO to map this view, then use your stored procedure to fill this view and this will be the fastest way to get your description fields.



I am sure there are many other ways but those are the ones I use. There are plenty of sample in the forum about using those methods, just search for "Custom Field Property" or "CFP" or "Browse Dialog" and have fun!
By Greg McGuffey - 12/11/2009

I see no issues with this approach, assuming your just using the dummy BO to get data. If you want to use it to update/add/delete data, it will get...er...interesting. Crazy



I used similar techniques for similar reasons (though it took me two years to figure out I could just type in the column names!) and it has worked great.



The single table thing is really only important when writing back to the db. It's pretty common to read all kinds of data into a BO. There are definitely different ways to do this, but not sure about better.



The only thing you might consider is looking into the FillMultipleDataTables method of a BO (static). This loads multiple BOs with one trip to the db and is a good thing to look into if a form is loading slowly. I had a form that was making something like 30 trips to the db when loading, due to a bunch of combos/lists. Switched to using FillMultipleDataTables, so all 30 got loaded at once and that really improved performance.
By Larry Caylor - 12/11/2009

As Greg pointed out the only issue is if you try to do an update, add or delete. The advantage of adding a dummy BO to the DDT is that all of the fields and property descriptors are generated for you. If you use scalar methods or add additional fields to your SELECT or stored procedures using a "real" BO, you have to add the custom properties and descriptors if you want to bind to them. However if you do an add, update, delete on a "real" BO, it will ignore the added fields. I've used both approaches. My only issue is that using the dummy BO results in "invalid" methods in the BO. At one time I was overriding the update, delete, and add methods to prevent any exception if they were called but I found it to be a lot of work. What I'd like to see is an additional BO class added to SF that was "read or lookup only" and had all of the add, delete, and update methods removed.
By Greg McGuffey - 12/11/2009

That's an excellent idea Larry. I second that suggestion!
By Ger Cannoll - 12/12/2009

Hi guys. Many thanks for all your comments which I have found very helpful.

The reson I thought that a Dummy BO would be the best of the available options to handle multiple joins is that it sems to be the most straightforward......just set up an additional Dummy BO with just one field...no need to set up views etc on the dataabase.

Also, these dummy BO would just be set up for lists (i.e. Read only) so unless I code something specifically in to 'Save' the Bo, there should be no possibility that attemps will be made to update the backend tables.....I will have a separate BO (the real BO) to do this.