Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking existence of lazy loaded child without getting/loading in Fluent NHibernate

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!

like image 447
Justin Avatar asked Aug 23 '09 03:08

Justin


3 Answers

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

like image 98
Daniel Auger Avatar answered Oct 30 '22 18:10

Daniel Auger


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

like image 4
Justin Avatar answered Oct 30 '22 16:10

Justin


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

like image 1
KLE Avatar answered Oct 30 '22 17:10

KLE