Inner join query

Posts   
 
    
anate
User
Posts: 8
Joined: 14-Dec-2010
# Posted on: 29-Dec-2010 19:33:57   

I am trying to use(inner join) query in MVC page. How can this be done using the Adapter.

SELECT A.AID,B.BID,C.ntext FROM TABLEA A INNER JOIN TABLEB B ON A.AID = B.BID INNER JOIN TABLEC C ON B.BID = C.CID INNER JOIN TABLED D ON A.TYPEID = D.TypeID where c.user_name = 'test'

I saw some examples online but I am not sure how to add relations between 3 or more tables. Please help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Dec-2010 02:51:22   

Hi there,

To add more relations just add them:

bucket.Relations.Add(TableAEntity.Relations.TableBEntityUsing...);
bucket.Relations.Add(TableBEntity.Relations.TableCEntityUsing...);
...

I assume that you already have mapped those relations into your LLBLGen project. Is that what you are looking for?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 30-Dec-2010 12:21:08   

Next time, please pick the right forum. Thanks.

Frans Bouma | Lead developer LLBLGen Pro
anate
User
Posts: 8
Joined: 14-Dec-2010
# Posted on: 30-Dec-2010 20:53:17   

Thanks for your hint. I added the relations. But I am trying to get the values from all these tables. Here is my code. How can I get the column values from TableA, TableB and TableC? This code only works for TableA. I couldn't get the column values from TableB and TableC.

EntityCollection TableACollection = new EntityCollection(new TableAEntityFactory()); RelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.Relations.Add(TableAEntity.Relations.TableBEntityUsingAid); bucket.Relations.Add(TableAEntity.Relations.TableCEntityUsingCId);

       using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntityCollection(TableACollection, bucket);
            foreach(TableAEntity tableAItem in TableACollection)
            {
                model.StartDate =tableAItem.StartDt.ToString();
             }
        }
Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 31-Dec-2010 11:08:33   

But I am trying to get the values from all these tables

If you want to pick values from more than one table (joined), in a flat way, then you should be using a DynamicList, not an entityCollection.