Using LINQ-to-NHibernate is there a way to narrow down what FetchMany()
returns?
Given the following class structure
public class Foo
{
public virtual int Id { get; set; }
public virtual IList<Bar> Bars { get; set; }
}
public class Bar
{
public virtual string Description { get; set; }
}
How can I do this:
session.Query<Foo>()
.Where(foo => foo.Id > 30)
.FetchMany(foo =>
foo.Bars.Where(bar => bar.Description.StartsWith("x")));
And NHibernate will return all Foo's with an Id > 30 and for those Foo's all the attached Bar's where the Bar's description starts with the letter 'x'?
I found some posts that use the old QueryOver()
stuff but I explicitely want to use NHibernate's LINQ provider.
Any ideas?
Update
I think I need to clarify what I want as a result.
<Foo Id="1">
<Bar Description="x1"/>
<Bar Description="b1"/>
</Foo>
<Foo Id="31">
<Bar Description="x2"/>
<Bar Description="x3"/>
<Bar Description="b2"/>
</Foo>
<Foo Id="32">
<Bar Description="b3"/>
</Foo>
From the data outlined above I expect the following result
<Foo Id="31">
<Bar Description="x2"/>
<Bar Description="x3"/>
</Foo>
<Foo Id="32"/>
The additional Where clause should only work on the Bar's! It should not further narrow down the list of Foo's! Just reduce what FetchMany()
returns.