I have the following models
public class Customer
{
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<Invoice> Invoices { get; set; }
public virtual XDocument AlotOfData { get; set; }
}
public class Invoice
{
public virtual long CustomerId { get; set; }
public virtual long Id { get; set; }
public virtual IList<LineItem> LineItems { get; set; }
public virtual XDocument AlotOfData { get; set; }
}
public class LineItem
{
public virtual long InvoiceId { get; set; }
public virtual long Id { get; set; }
public virtual double Amount { get; set; }
public virtual XDocument AlotOfData { get; set; }
}
If i do just a normal nhibernate query to get a customer it would look like below.
long customerId = 1;
Customer customer = Session.QueryOver<Customer>().Where(x => x.Id == customerId).SingleOrDefault();
if i have lazy="false" in my mapping files for all child collections it will result in the following Sql Queries being executed
1 query to get the Customer (only selecting columns from Customer table)
1 query to get all the Invoices for that customer (only selecting columns from Invoice table)
n queries to the LineItems table (one query for each Invoice only selecting columns from LineItems table)
What i would like to know is how do i keep the same queries that are currently being executed but instead of nhibernate making n seperate queries to the LineItems table it will only make 1. Is there a way that this can be done either by an in clause or a join to the invoice table but not selecting the columns from the invoice table.
Thanks Jeremy