inner join on alias

Posts   
 
    
silky avatar
silky
User
Posts: 38
Joined: 03-Feb-2008
# Posted on: 08-May-2008 07:58:34   

is it possible to create a query of the form:


select
  *
from
  tblTransactions
inner join
  tblAccounts
  alAccountsSide1 on
  alAccountsSide1.AccountID = tblTransactions.AccountID1
 inner join
  tblAccounts
  alAccountsSide2 on
  alAccountsSide2.AccountID = tblTransactions.AccountID2

as far as i can tell, the answer is no. i hope i'm wrong.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-May-2008 08:34:14   

It's my pleasure to tell you that you are wrong. wink

You can join to the same table/entity more than once by specifying the relation more than once.

And the RelationCollection.Add() method has an overload that accepts an alias.

public IEntityRelation Add( 
   IEntityRelation relationToAdd,
   string aliasRelationEndEntity
)
silky avatar
silky
User
Posts: 38
Joined: 03-Feb-2008
# Posted on: 08-May-2008 08:41:41   

sadly i don't think that does what i need.

i saw it used in the documentation, and it was used to create a string that is referenced later in a predicate expression. i don't need that.

my current llblgen code is:

bucket.Relations.Add(TransactionsEntity.Relations.AccountsEntityUsingAccountId2);
bucket.Relations.Add(AccountsEntity.Relations.StoresEntityUsingDefaultAccountId);

// 1 bucket.Relations.Add(TransactionsEntity.Relations.AccountsEntityUsingAccountId1);
// 2 bucket.Relations.Add(AccountsEntity.Relations.CustomersEntityUsingDefaultAccountId);

note the two commented out lines. line 2 needs to refer to the 'account' part that is joined in line 1. is it possible to do that?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-May-2008 09:01:56   
bucket.Relations.Add(TransactionsEntity.Relations.AccountsEntityUsingAccountId2);
bucket.Relations.Add(AccountsEntity.Relations.StoresEntityUsingDefaultAccountId);

bucket.Relations.Add(TransactionsEntity.Relations.AccountsEntityUsingAccountId1, "Acc1");
bucket.Relations.Add(AccountsEntity.Relations.CustomersEntityUsingDefaultAccountId, "Acc1", "Cus", JoinHint.None);
silky avatar
silky
User
Posts: 38
Joined: 03-Feb-2008
# Posted on: 08-May-2008 09:03:13   

Thanks a lot Walaa smile