How do I test if there is a related entity?

Posts   
 
    
havoc1
User
Posts: 8
Joined: 06-May-2005
# Posted on: 09-May-2005 15:22:31   

Hi, I am working with the Adapter. I have a CaseEntity which may or may not have a related BankAccount entity. I am retrieving the BankAccount as below, and am struggling to find a way that I can use to test whether there is a related BankAccount or not other than wrapping the whole thing in a try...catch. Can you tell me if this is the correct way, and if not suggest another?

Thanks

CaseEntity selectedCase = new CaseEntity(1); myAdapter.FetchEntity(selectedCase);

// Now find it's related bank account in the join table selectedCase.CaseBankAccount = (CaseBankAccountEntity)myAdapter.FetchNewEntity(new CaseBankAccountEntityFactory(), selectedCase.GetRelationInfoCaseBankAccount());

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 09-May-2005 19:19:05   

havoc1 wrote:

Hi, I am working with the Adapter. I have a CaseEntity which may or may not have a related BankAccount entity. I am retrieving the BankAccount as below, and am struggling to find a way that I can use to test whether there is a related BankAccount or not other than wrapping the whole thing in a try...catch. Can you tell me if this is the correct way, and if not suggest another?

Thanks

CaseEntity selectedCase = new CaseEntity(1); myAdapter.FetchEntity(selectedCase);

// Now find it's related bank account in the join table selectedCase.CaseBankAccount = (CaseBankAccountEntity)myAdapter.FetchNewEntity(new CaseBankAccountEntityFactory(), selectedCase.GetRelationInfoCaseBankAccount());

After that code, do: if(selectedCase.CaseBankAccount.Fields.State==EntityState.Fetched) { // bankaccount available }

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 09-May-2005 20:01:31   

havoc1 wrote:

Hi, I am working with the Adapter. I have a CaseEntity which may or may not have a related BankAccount entity. I am retrieving the BankAccount as below, and am struggling to find a way that I can use to test whether there is a related BankAccount or not other than wrapping the whole thing in a try...catch. Can you tell me if this is the correct way, and if not suggest another?

Thanks

CaseEntity selectedCase = new CaseEntity(1); myAdapter.FetchEntity(selectedCase);

// Now find it's related bank account in the join table selectedCase.CaseBankAccount = (CaseBankAccountEntity)myAdapter.FetchNewEntity(new CaseBankAccountEntityFactory(), selectedCase.GetRelationInfoCaseBankAccount());

I would use prefetch paths and then test for nulll on CaseBankAccount...

Jeff..

<Edit> Oops, left the reply message up too long and responded just after the buzzer. simple_smile