Exception when unfetched entity references are accessed

Posts   
 
    
Ries
User
Posts: 46
Joined: 23-Aug-2006
# Posted on: 02-Jul-2008 00:19:41   

When I forget to pre-fetch an entity using the Adapter classes, I would like to get an exception when I try to access that entity though a related object.

For example: I pre-fetched Customers, but not Orders. The code:

Console.Write(myCustomer.Orders.Count);

should ideally throw an exception indication that Orders was never fetched,as opposed to 'gracefully' displaying '0'.

Would you consider adding a property-property to LLBLGen that would generate code to do that?

Thanks

Ries - Amsterdam Software

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Jul-2008 05:30:14   

Hi Ries,

That's tricky. What if you write:

myCustomer.Orders.Add(...);
// or
if (myCustomer.Orders.Count >0 )
{
     // do something
}

Should that throw an exception too?

Here is an old and large discussion about that subject, the reasons, etc: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=2013

David Elizondo | LLBLGen Support Team