db4o:LINQ相当于SODA查询?

时间:2011-02-23 18:36:16

标签: linq db4o soda

对于db4o,我正在尝试查找生成以下SODA的LINQ代码:

    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();

所有SODA都会将树下拉到结束节点。例如,如果您想为“2010-10-18”日期选择“APPLE”,它将返回“星期四的苹果”。

数据结构:

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"

这是我的第一次尝试,它不能用于获取交叉产品(即查看每种可能的组合)。我不能使用连接,因为db4o是一个对象数据库,并且您无法访问每个对象的ID,例如在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
                          };

1 个答案:

答案 0 :(得分:1)

你真的想直接想用query.Descend("Symbol");下降到“符号”吗?我想你想约束'符号'这个类型。我只是假设你是这个意思:

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();

不是100%肯定,但应该是这样的:

// 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;