Wooo-hooo What a trip!

Posts   
 
    
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 29-Dec-2004 21:10:50   

I spent the last two days trying to debug an InvalidCastException error that was generated because I prefetched to an ancester:


IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.AccountEntity) ;
prefetchPath.Add(AccountEntity.PrefetchPathManagerContact) ; 
/* NOTE!  Above line SHOULD be: "prefetchPath.Add(Account).PrefetchManagerContact".  AccountEntity is an ancester of Account.  This code compiles but generates an InvalidCastExpection that is VERY difficult to debug!!! */
ent = new Account (key) ;
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntity(ent, prefetchPath) ;

... elsewhere...
... MessageBox.Show ("Contact name is: " + (Account)accountEntity).ManagerContact.ContactName) // OOPS!  InvalidCastException at runtime!!

Anyway, this is a heads-up to all you good LLBLGenPro coders.

Happy New Year.

Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Dec-2004 09:22:44   

Seems indeed a horrible bug to track down... The code has build in checking if the path node is suitable for the path it's added to, but that's on the entity level. derived classes as you use them are of the same entity, so that check succeeded...

Frans Bouma | Lead developer LLBLGen Pro