views:

299

answers:

3

This should be easy, but I can't seem to figure it out... How can I check if a child on an entity exists without actually getting or fetching it? The child is lazy loaded right now..

so I have two entities:

class A
{
    public virtual int Id { get; set; }
    public virtual B Child { get; set; }
}
class B
{
    public virtual int Id { get; set; }
    public virtual byte[] Blob { get; set; }
}

I want to check for existence of B in an instance of A without actually fetching the large blog... In straight sql I could just check to see if child_id is not null... Is there some way I can query the NHibernate Proxy of B in A?

Thanks!

+1  A: 

nm - one can just check for a null value. Only if a child exists will there be a proxy.

Justin
A: 

The null-value check is the perfect solution : efficient, understandable.

KLE
+1  A: 

NHibernateUtil.IsInitialized(...) will tell you if a proxy object has been loaded.

Daniel Auger