I'm creating this kind of tree data structure with 4 or 5 levels from related collections of monthly volume data for car manufacturer, model, and engines etc. It's taking up to a minute to build it though. Is there a faster way of doing it?
var carData = (from manufacturer in manufacturerMonths.Select(m => m.Manufacturer).Distinct()
select new
{
ManufacturerData = (from manufacturerMonth in manufacturerMonths
.Where(t => t.Manufacturer == manufacturer)
select new
{
Date = manufacturerMonth.Date,
Volume = manufacturerMonth.Volume,
Models = new
{
ModelsData = (from model in modelMonths
.Where(m => m.Manufacturer == manufacturer)
.Select(m => m.Model).Distinct()
select new
{
ModelData = (from modelMonth in modelMonths
.Where(m => m.Model == model)
select new
{
Date = modelMonth.Date,
Volume = modelMonth.Volume,
Engines = new
{
EnginesData = (from engine in engineMonths
.Where(e => e.Model == model)
.Select(e => e.Engine).Distinct()
select new
{
EngineData = ....
}
}
}
}
}
}
}
}