0
public class Parent
{
    public virtual long Id { get; set; }
    public virtual string Name { get; set; }
    public virtual List<Child> Children { get; set; }
}

public class Child
{
    public virtual long Id { get; set; }
    public virtual string Description { get; set; }
    public virtual Parent Parent { get; set; }
}

In NHibernate, how can I get a list of children with their parent name using only one call to db. I tried:

CurrentSession.QueryOver < Child>().JoinQueryOver(x=>x.Parent).Fetch(x => x.Parent).Eager.List< Child>().ToList();

but it didn't work.

The mappings are done using FluentNHibernate.

Dan Nick
  • 132
  • 1
  • 2
  • 12

1 Answers1

1

so close:

CurrentSession.QueryOver<Child>()
  .Fetch(x => x.Parent).Eager
  .List<Child>();

should work (you don't need the extra call to .ToList, or the join on to Parent)

Martin Ernst
  • 5,629
  • 2
  • 17
  • 14