Whats the correct LINQ to navigate to the end leaf node of the following data structure?
Root ----Symbol (APPLE)
| |------Day 1: Date: 2010-10-18, string "Apples on Thursday"
| |------Day 2: Date: 2010-10-19, string "Apples on Friday"
|
|
|-----Symbol (PEAR)
|------Day 1: Date: 2010-10-18, string "Pears on Thursday"
|------Day 2: Date: 2010-10-19, string "Pears on Friday"
In other words, if I select "APPLE", then "2010-10-19", it should return "Apples on Friday".
The following does not work (it selects from the Cartesian Product which is every single combination) of symbol and date):
var daysForSymbolS1 = from Symbol s in db4o.db
from Date t in db4o.db
where (s.SymbolGlobal == "APPLE"
&& t.Date == new DateTime(2010, 10, 18))
select new
{
s.SymbolGlobal,
t.Date,
t.Meta
};
foreach (var d in daysForSymbolS1)
{
Console.WriteLine("{0} - {1} - {2}", d.SymbolGlobal, d.Date.Date, d.Meta);
}
I'd love to use a join - but db4o is an object database, and it doesn't let you reference the ID for each object.
Update:
@Gamlor gave a brilliant answer, it works like a charm.
I should also mention that the current version of db4o does not support indexing on collections. Since any form of 1-to-many hierarchy is constructed using something like an IList collection that holds some subclasses, it is likely that breaking the database down into a hierarchy will slow things down, both speed and maintenance wise.