score:0

perhaps not exactly what you're after, but certainly worth considering is the nhibernate.collectionquery library.

it allows you to query uninitialized nhibernate collections on an entity using linq - but would require an additional query/round-trip to get them (unlike fetchmany, which grabs the entire collection in the same round-trip).

score:0

you will need a reference from child object to the parent.

var result = from foo in session.query<foo>().fetchmany(f => f.bars)
             from bar in session.query<bar>()
             where foo.id == bar.fooid && // fooid is missing in your entity
                   foo.id > 30
                   bar.description.startswith("x")
             select foo;

score:1

i'm fairly sure you're out of luck with the current linq provider - but for a non-linq (and cross-cutting) option, you might want to have a look at the filter functionality included in nhibernate - it would probably be the best bet for implementing this in a large scale / complex project.

score:1

var query = from foo in session.query<foo>()
            where foo.id >30
            from bar in foo.bars
            where bar.description.startswith("x")
            select new { id = foo, bar = bar};
var results = query.tolist().tolookup(x => x, x => x.bar);
foreach(var foo in results.keys)
{
   var barswhichstartwithx = results[foo];
   //do stuff
}

although this may produce inefficient sql (i don't use nhibernate so i wouldn't know). you could also try this...also the above would miss out foos without bars.

var foosquery = session.query<foo>().where(foo => foo.id > 30);
var foos = foosquery.future();
var barsquery = from f in foosquery
                from bar in foo.bars
                select new { id = foo.id, bar = bar};
var foosdict = foos.todictionary(x => x.id);
var bars = barsquery.tolist().tolookup(x => foosdict[x.id], x => x.bar);
foreach(var foo in foos)
{
   var barswhichstartwithx = bars[foo];
   //do stuff
}

Related Query

More Query from same tag