Retrieving data from 2 tables in a ReadOnlyListBase Class

Retrieving data from 2 tables in a ReadOnlyListBase Class

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


edgarrezende posted on Wednesday, June 10, 2009

Hello all,

I have a class called ContactList which inherits from ReadOnlyListBase. This is working quite well but now I need a ContactList PLUS information from another table called sec_user (currently this ContactList class is only retrieving data from one table called Contact) .So my question is: do I have to create another ReadOnlyListBase class called for example ContactSecuserList in order to obtain a list from two tables? Or is there a way I can use this existing ContactList to implement this especial query ? What is the best way of obtaining a list from 2 tables?

I don't want to break the CSLA architecture which  -- unfortunately -- I don't know very well yet.

Thanks for any clue!
Edgar

JoeFallon1 replied on Wednesday, June 10, 2009

It is possible to use a single object but I do not recommend it. It just gets confusing.

So your best bet is to create a 2nd object that has the extra properties in it. The SQL statment should do a JOIN on the 2 tables and pull back all the fields in one shot. Then populating the new list is done the same way as the other one (just with the extra fields.)

If you want to go with a single List then you have to realize that these extra properties will be blank when you populate the list of the first type and filled in for the 2nd type. You only need to branch your code on the SQL statement definition and when filling from the dr test that the extra fields are not present. Perhaps set a flag in your SQL branch so you know they are absent. As you can see this is really hacking things up just to avoid making a 2nd BO.

Joe

edgarrezende replied on Wednesday, June 10, 2009

Well said, thanks for the insight.
Best,
Edgar




Copyright (c) Marimer LLC