In iBatis with C#, how to check for if a lazy loaded property is null

276 Views Asked by At

I have an object (Cart) which have a one-to-one relation to a Case. This relation is allowed to be null and is lazyloaded. So sometimes a Cart has a case, sometimes it doesn't. And if it does have a case it not loaded until it is needed.

If it wasn't lazyloaded I could do this:

if (cart.Case !=null)
{
 // do something with cart.Case
 var x = cart.Case.SomeProperty;
}

However, this fails with an error because cart.Case is never null. It is a proxy object. So what to do? I guess I could use try/catch, but then I would have to do that every single time I access a property of cart.Case.

1

There are 1 best solutions below

0
On

I ended up using try/catch. Works fine, but I still think it is not the right way to do it.