I have a case where I need to load about 10 000 objects from database. The data model is something like this:
public class SimulationObject
{
public Container Container {get;set;}
public IList<ResultItem> Results {get;set;}
public IList<PreviewData> PreviewData {get;set;}
...
}
public class ResultItem
{
public IList<SomeDataItem> Items {get;set;}
...
}
public class PreviewData
{
public IList<SomeDataItem> Items {get;set;}
...
}
This means that I want to query a list of SimulationObjects from database according to some query, and all of it's properties (references) and subitems.
The quantities of collections are the following:
- SimulationObject - ca 6000 - 1200, depending on parameters in "where"
- SimulationObject.Results - ca 5 to 40 items
- SimulationObject.Results.Items - ca 0 to 2 items
- SimulationObject.PreviewData - ca 0 to 2 items
- SimulationObject.PreviewData.Items - ca 1 to 3 items
Normally, I'd do it like this:
var query = from sim in session.Query<SimulationObject>()
where sim.Container.Id == containerId && ...
select sim;
query = query.FetchMany(c => c.Results).ThenFetch(o => o.Items)...
However, I also need to fetch "PreviewData" items for that would create a Cartesian product in my query (meaning PreviewDataAndSubItemsCount x ResultsAndSubItemsCount amount of rows returned) which is very ineffective. Also, as I need to load a LOT of SumulationObjects (about 10000 as sayd earlier), I cannot do lazy loading (10000 queries..and there are other difficulties too, so this isn't even an alternative to consider).
So what are the alternatives ? What strategy would you use to load a complite object graph into memory ?
Thanks.