I believe the only way to do this would be to use QueryOver/Criteria/ HQL to do a query which eager loads the lazy loaded collection with a left outer join. You would then apply a where clause to the alias. Which would allow you to filter which items in the collection are actually loaded.
Aside from CreateFilter the only other way I have found for doing this is by using ISession.Filter which allows you to pass the proxy for the lazy-loaded collection and a HQL query (IIRC) as a parameter and receive as a result the filtered collection. Of course now you either need to move the logic that operates on the filtered collection outside of the class that owns the lazy-loaded collection or take a dependency on NH's Session in your class, which is not what you wanted. What would be nice is if the Lazy Loaded collection proxy could process a LINQ query. It seems this type of behavior would be perfect for the semantics of "lazy=extra". Hopefully something like this will be added otherwise the pre-fetching method is the cleanest mechanism I have found so far. On Jan 24, 7:44 pm, Joseph Daigle <[email protected]> wrote: > I have a lazy-loaded collection that I would like to filter at > runtime. For instance I may want to filter the collection so that I > SELECT only a subset of the related entities. > > I understand how to use ISession.CreateFilter(), but I would like to > do this type of filtering from within the class which contains the > collection. I definitely do not want my class having a reference to > ISession as this significantly reduces the testability of my domain > model. > > Are there any other alternatives or approaches for executing this kind > of query, while still maintaining a reasonable level of encapsulation > and high testability? > > Thank you, > > -- > Joseph Daigle -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
