I want to do a QueryOver on an object for which I want to do an outer join on its sublist only if the current object has a property set to true.
Let's say you have an object Store which has a list of Product, and Product has a sublist Phone
The object Store has a boolean property HasAllProducts.
If HasAllProducts is true, then Store doesn't need to know the list of products, so no outer join is needed.
IfHasAllProducts is false, then Store has to know its list of Products so an outer join is needed, and another outer join is needed between Product and Phone
So I would like a query like
session.QueryOver<Store>(() => storeAlias)
if (!storeAlias.HasAllProducts)
{
.Left.JoinAlias(s => s.Products, () => productAlias)
}
.Future<Store>();
//Then again to avoid catersian product
if (!storeAlias.HasAllProducts)
{
session.QueryOver<Product>(() => productAlias)
.Left.JoinAlias(p => p.Phones, () => phoneAlias)
.Future<Phone>();
}
I know that for the first join, you can use withClause, but how would you perform (or not perform) the second conditional join? it should not be executed if no Phoneis fetched in the previous query.
The problem with with clause is that it will generate a query in all cases, I would like to avoid running two additional queries if it's not needed.
I would suggest 2 queries.
Another option is to use CollectionBatchSize to not eager load here but use lazy loading with batches on usage