You can do this with the QueryOver/Criteria/HQL methods for querying. Just construct a query rooted at ThirdParty with a left outer join to the child collection and apply your where clause and your off to the races. Right now it does not seem like this is possible with the LINQ API because it doesn't support left outer joins, and NHibernate only seems to load the data returned in the select statement of the generated SQL query when a left outer join is used to pull the data in.
On Dec 7, 11:11 am, Kakone <[email protected]> wrote: > Hello, > > I try to find a way to filter children collection in LINQ. I know I > can enable a filter on the session, but the filter string is native > SQL, I don't want to use this. > With Criteria, I think I can use a result transformer > (Transformers.AliasToEntityMap) to achieve this, but is there a way to > do this with the new LINQ provider ? > > For example, I've got two classes : > > public class ThirdParty : Entity > { > public virtual string FirstName { get; set; } > public virtual string LastName { get; set; } > > public virtual ThirdParty CurrentParent > { > get > { > var thirdPartyAssignment = > Assignments.FirstOrDefault(tpa => tpa.EndDate == null); > return thirdPartyAssignment == null ? null : > thirdPartyAssignment.ThirdParty; > } > } > > public virtual IEnumerable<ThirdPartyAssignment> Assignments > { get; set; } > > } > > public class ThirdPartyAssignment : Entity > { > public virtual ThirdParty ThirdParty { get; set; } > public virtual ThirdParty Parent { get; set; } > public virtual DateTime? EndDate { get; set; } > > } > > Sometimes, I want all the ThirdParties with all the Assignments (in > this case, session.Query<ThirdParty>() works well). Other times, I > want the ThirdParties with only the Assignments where EndDate is null. > I didn't succeed to do this with the LINQ provider. > > Cordially, > Kakone. -- 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.
