Hi,

you cal query separatey in the same session/transaction and nhibernate 
reconstruct collections

1) open session trasnsaction
2) load  place for your matches
3) load stores for your matches
3) load for your matches
4) close session transaction

now nhibernate don't load entities collection if exist in session..

 check for IsInitialized before access collection... so not initialized 
stores collection mean not match your criteria... and you don't trigger 
lazy load collection

sorry for my english 

t.

Il giorno mercoledì 13 aprile 2016 22:51:52 UTC+2, Lars Halvor Anundskås ha 
scritto:
>
> Hi,
>
> This is a question regarding filtering/criterias on associated entities :)
>
> I have 3 entities:
>
> Place
> Store
> Owner
>
> A Place has many stores, a store has one owner, 
> an owner can have many stores, a store have one place.
>
> When I do a query for places I'm looking for a way to control which 
>  stores are loaded in place.Stores collection.
> For instance, I want all places, but I only want to return the store if 
> the owner is Mike.
>
> Is there any way to do this with nhibernate, using criterias or filters?
>
> I have tested multiple variants but I always get all stores related to the 
> place, for instance:
>
> Session.CreateCriteria(typeof(Place))
>                     .CreateAlias("Stores", "s", JoinType.InnerJoin)
>                 .Add(Restrictions.Eq("s.Owner", "Mike"));
>
> But I always get all stores listed, regardless of the owner.
>
> Is it possible to achieve this, how?
> Greatful for any hints/tips/solutions.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to