Search code examples
linqdb4osoda

db4o: LINQ equivalent of SODA query?


For db4o, I'm trying to find the LINQ code that generates the following SODA:

    var query = db4o.db.Query();
    query.Descend("Symbol");        
    query.Descend("_symbolGlobal").Constrain("APPLE");
    query.Descend("_date"); // Add a date constraint here.
    IObjectSet result = query.Execute();

All the SODA does is drop down the tree to an end node. For example, if you wanted to select "APPLE" for date "2010-10-18", it would return "Apples on Thursday".

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"

Here is my first attempt, which doesn't work as its getting the cross product (i.e. its looking at every possible combination). I can't use a join, as db4o is an object database and you don't have access to the ID for each object, like in a RDBMS.

    var stringForDayAndSymbol = from s in db4o.db.Query<Symbol>(a => a.SymbolGlobal == "APPLE")
                          from t in db4o.db.Query<Date>(b => b.Date == new DateTime(2010, 10, 20))
                          select new
                          {
                            s.SymbolGlobal,
                            t.Date,
                            t.Meta
                          };

Solution

  • Do you really directly want to descent into "Symbol" with query.Descend("Symbol");? I guess that you want to constrain for the type 'Symbol'. I just assume that you meant this:

    var query = db4o.db.Query();
    query.Constrain(typeof(Symbol));        
    query.Descend("_symbolGlobal").Constrain("APPLE");
    query.Descend("_date"); // Add a date constraint here.
    IObjectSet result = query.Execute();
    

    Not 100% sure, but should be something like this:

    // I assume here that the field _symbolGlobal is accessable with the property SymbolGlobal
    // and the field _date is accessable with the property Date
    var result = from Symbol s in db4o.db
                where s.SymbolGlobal == "APPLE"  
                select s.Date;