Using LINQ to query nested classes in db4o? -
run tricky problem db4o , simple nested structures.
problem: when use linq pull data out of db4o, pulling out data (i.e. "where" clause doesn't seem working).
i have nested objects:
root ----symbol (spx) | |------day 1: date: 2010-10-18, string "spx meta" | |------day 2: date: 2010-10-19, string "spx meta" | | |-----symbol (ibm) |------day 1: date: 2010-10-18, string "ibm meta" |------day 2: date: 2010-10-19, string "ibm meta"
i create 2 symbols:
symbol sym1 = new symbol("spx"); symbol sym2 = new symbol("ibm");
i create trading days:
// spx tradingday day1 = new tradingday(new datetime(2010, 10, 18), "spx meta"); tradingday day2 = new tradingday(new datetime(2010, 10, 19), "spx meta"); // ibm tradingday day3 = new tradingday(new datetime(2010, 10, 18), "ibm meta"); tradingday day4 = new tradingday(new datetime(2010, 10, 19), "ibm meta");
i assign couple of days each symbols:
sym1.assigntradingday(day1); sym1.assigntradingday(day2); sym2.assigntradingday(day3); sym2.assigntradingday(day4);
i persist db4o object database:
// store in database. db4o.db.store(sym1); db4o.db.store(sym2); db4o.db.commit();
pretty simple far.
i check database "db4o object manager enterprise", , sure enough, there 2 symbols, , if click on each symbol, each 1 contains 2 days.
now, linq query pull data out:
var daysforsymbols1 = symbol s in db4o.db tradingday t in db4o.db (s.symbolglobal == "ibm" && t.date == new datetime(2010, 10, 19)) 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); }
and, weird happens:
ibm - 10/19/2010 12:00:00 - spx meta // line should not appear because have specified "ibm" in filter. ibm - 10/19/2010 12:00:00 - ibm meta
despite fact specified should return data "spx" returning data "ibm" well.
am doing wrong?
you didn't post exact definition of classes doing cartesian product in linq query - creating every possible combination whereas want "matching" combinations (since trading day in schema reason seems associated symbol). should instead join, like:
tradingday t in db4o.db join symbol s in db4o.db on s.symbolglobal equals t.symbolglobal (s.symbolglobal == "ibm" && t.date == new datetime(2010, 10, 19)) ...
Comments
Post a Comment