I have this query:
IQueryable<OrderEntity> _records = All().Fetch(x => x.client).FetchMany(x => x.orderItems).ThenFetch(y => y.righeDistinte);
Simplyfing for the matter of this question, these are the involved entities:
public class OrderEntity : IEntity
{
public virtual ClientEntity client { get; set; }
public virtual ICollection<OrderItemEntity> orderItems { get; set; }
}
public class ClientEntity
{
public virtual String cod_clifor { get; set; }
public virtual String des_ragsoc { get; set; }
}
public class OrderItemEntity
{
public virtual ICollection<DistintaItemEntity> righeDistinte { get; set; }
}
public class DistintaItemEntity
{
public virtual OrderItemEntity orderItem { get; set; }
public virtual DistintaEntity distinta { get; set; }
}
So, each OrderEntity instance references one ClientEntity and 0 to many OrderItemEntity objects. In turn, each OrderItemEntity can reference 0 to many DistintaItemEntity.
The query on top of this post returns the collection of all orders with the related client and orderitems and each orderitem has the distintaitementity fetched (all mappings are well set). All in just one SQL query.
So far, so good.
The problem is with DistintaEntity, which is not forced loaded, so if I want to access some of its properties I need to have the session open because of lazy loading (as long as there's an open session, it works, but there are additional queries of course).
I'd like to add to the query a directive to force direct fetch of the DistintaEntity object associated with each DistintaItemEntity, but I don't know how to do it without loosing the single query result.
All one to many relations are left join.
Thanks, Mario